PHP:
$cards = array("Messi ", "Ronaldo ", "Ibrahimovic ", "Ribery ", "Robben ", "Neymar ", "Rooney ", "Casillas ", "Falcao ", "Van Persie ", "Hazard ");
shuffle($cards);
echo $cards[0]
我想制作一系列图像。我的想法是,它不是回显/打印文本,而是从数组列表中打印/回显图像,但我该如何做呢?我创建了一个随机化所选字符串的数组,但我不知道从哪里开始通过数组显示图像。请帮忙! :)
答案 0 :(得分:1)
此脚本将使数组随机播放,然后为每个播放器打印图像。假设每张图片都是jpg。
$cards = array("Messi", "Ronaldo", "Ibrahimovic", "Ribery", "Robben", "Neymar", "Rooney", "Casillas", "Falcao", "Van Persie", "Hazard");
shuffle($cards);
foreach ($cards as $card) {
echo "<img src='imagesDirectory/$card.jpg'> <br>";
}
如果您只想打印一张卡片,请删除foreach并写下:
$card = $cards['0'];
echo "<img src='imagesDirectory/$card.jpg'> <br>";
如果您想要显示固定数量的卡片:
$numberOfCards = 10; // this is the number of cards you want to show
for ($i=0; $i <= $numberOfCards ; $i++) {
$card = $cards[$i];
echo "<img src='imagesDirectory/$card.jpg'> <br>";
}