Is it possible to iterate through instead of using switch statement using only PHP? I have weekdays in array, and the matching weekdays in the dropdown menu. The switch statement works, but for longer arrays I'm wondering how I would go about matching them in order to output. I'm a newb and not sure if it's possible to iterate through in this scenario.
<p><select name="weekDay" style=" height:21px; width:96px;">
<option value="">Choose:</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
</p></select>
<input type="submit" name="submit" style="margin-left:10px;"> </div>
<?php
$Week = array("Monday" => '<img src="mon.jpg">',"Tuesday" => '<img src="tues.jpg">', "Wednesday" => '<img src="wed.jpg">', "Thursday" => '<img src="thurs.jpg">', "Friday" => '<img src="fri.jpg">',"Saturday" => "<p style='color:white;'>No images on Weekends!</p>","Sunday" => "<p style='color:white;'>No images on Weekends!</p>");
switch($_POST['weekDay']){
case 'Monday':
print $Week['Monday'];
break;
case 'Tuesday':
print $Week['Tuesday'];
break;
case 'Wednesday':
print $Week['Wednesday'];
break;
case 'Thursday':
print $Week['Thursday'];
break;
case 'Friday':
print $Week['Friday'];
break;
default:
if(isset($_POST['submit'])){
print ('<p style="color:red;">Oops! Be sure to choose a day of the week!</p>');
}
}
$Day = date("l");
print("</br><p style='color:white; margin-top:70px;'>The pic for $Day (today's date) is:</p>");
print("<p> $Week[$Day]!</p>");