-5

我有产品列表,从女巫那里我需要随机显示四个项目。

<?php 

// my product list
function productlistX {
    $array = array( 

        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};

    )

    // need to display 4 random products from the array above 
    foreach  {
        echo "<li>".$name . $link . $img . "</li>"
    }
}

// display these random products in my ajax tab (products.php?order=mytab)
$data['mytab'] = $productlistX;

if (isset($data[$_GET['order']])) { 
    echo $data[$_GET['order']];
} 
?>

如您所见,我的列表蚂蚁只需要随机显示列表中的四个项目。

提前致谢!

4

2 回答 2

2

这可以通过 phprand()函数来完成,或者您也可以使用array_rand来使用数组 rand 首先您需要创建数组

于 2012-09-17T17:41:07.323 回答
0

不确定我是否知道text-php文件类型是什么,但生成四个数字并继续阅读,直到显示所有四个数字。或者阅读整篇文章并从中选择。

于 2012-09-17T17:40:43.680 回答