This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
PHP provides another control structure called a "switch" statement. Switch statements are similar to a series of IF statements that use the same expression. Switch statements allow you to compare many different values with the same variable or expression. For example: you may want to look at the day of the week, and perform different actions based on which day of the week it is.
Documentation
Weekly Chores
Pioneering Journeys of the Ingalls Family
switch (date('l')) {
case "Monday":
echo "Wash on Monday";
break;
case "Tuesday":
echo "Iron on Tuesday";
break;
case "Wednesday":
echo "Mend on Wednesday";
break;
case "Thursday":
echo "Churn on Thursday";
break;
case "Friday":
echo "Clean on Friday";
break;
case "Saturday":
echo "Bake on Saturday";
break;
case "Sunday":
echo "Rest on Sunday";
break;
default:
echo "I don't know what day it is";
break;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up