我有一项任务,必须根据用户选择的号码奖励随机奖品。一旦选择了该号码,就会存储它并对阵列进行洗牌并显示奖品。我已经想到了,但我还需要根据最终获得的奖项来显示文字,并且我会被卡住。
$award = array("bmw.jpg", "puppy.jpg", "grocery.jpg", "pen.jpg", "gas.jpg", "iphone.jpg");
shuffle($award);
?>
<?php
echo '<img src="'. $award[$_GET["number"]].'" width="217" align="middle" >';
if($award['. $award[$_GET["number"]].'] == "bmw.jpg")
{
echo '<p>Congrats you won the grand prize</p>';
}
?>
答案 0 :(得分:0)
像这样更改你的if语句:
<?php
if($award[$_GET["number"]] == "bmw.jpg")
{
echo '<p>Congrats you won the grand prize</p>';
}
?>
希望这会有所帮助。
答案 1 :(得分:0)
$award = array("bmw.jpg", "puppy.jpg", "grocery.jpg", "pen.jpg", "gas.jpg", "iphone.jpg");
shuffle($award);
$text = array("BMW", "Puppy", "Grocery", "Pen", "Gas", "Iphone");
?>
<?php
echo '<img src="'. $award[$_GET["number"]].'" width="217" align="middle" >';
if($award[$_GET["number"]] == "bmw.jpg")
{
echo '<p>Congrats you have won '.$text[$_GET["number"]].' the grand prize</p>';
}
?>