Kiotzu Kiotzu - 1 month ago 16
PHP Question

Need text to be displayed based on value of array

I have an assignment where a random prize must be awarded based on the number the user chooses. Once that number is chosen it is stored and the array is shuffled and the prize is displayed. I have that figured out but I also need text to be displayed based on what prize it ends up being and im getting stuck.

$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>';
}
?>

Answer

change your if statement like this:

<?php

if($award[$_GET["number"]] == "bmw.jpg")
{
   echo '<p>Congrats you won the grand prize</p>';
}
?>

hope this helps.