可能重复:
列表中的 php 循环随机产品
我需要产品列表,从女巫那里我可以随机显示 4 件商品。
我曾尝试编写 php 代码,但需要语法和变量方面的帮助才能完成。
<?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']];
}
?>
提前致谢!