Switch statement execution
📖 Scenario: You are creating a simple program to display the day of the week based on a number input. This is like a small calendar helper that tells you the name of the day when you enter a number from 1 to 7.
🎯 Goal: Build a PHP program that uses a switch statement to print the correct day name for a given number.
📋 What You'll Learn
Create a variable called
dayNumber with a value from 1 to 7Create a variable called
defaultDay with the value 'Invalid day'Use a
switch statement on dayNumber with cases for numbers 1 to 7Print the day name corresponding to the number (1 = Monday, 2 = Tuesday, ..., 7 = Sunday)
Print
defaultDay if the number is not between 1 and 7💡 Why This Matters
🌍 Real World
Switch statements are useful when you want to choose between many options based on a single value, like menu choices or day names.
💼 Career
Understanding switch statements helps in writing clear and efficient code for decision-making in many programming jobs.
Progress0 / 4 steps