0
0
PHPprogramming~15 mins

Nested conditional execution in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested conditional execution
📖 Scenario: You are creating a simple PHP program to decide what message to show based on the weather and time of day.
🎯 Goal: Build a PHP script that uses nested if statements to check the weather and time, then prints the correct message.
📋 What You'll Learn
Create variables for $weather and $time with exact values
Add a variable $isWeekend to indicate if it is weekend
Use nested if statements to check $weather and $time
Print the correct message based on conditions
💡 Why This Matters
🌍 Real World
Nested conditions help programs make decisions based on multiple factors, like weather and time, similar to how apps show different messages or options.
💼 Career
Understanding nested conditional execution is essential for programming logic in web development, automation scripts, and many software applications.
Progress0 / 4 steps
1
DATA SETUP: Create weather and time variables
Create a variable called $weather and set it to the string "sunny". Also create a variable called $time and set it to the string "morning".
PHP
Need a hint?

Use = to assign the string values to the variables.

2
CONFIGURATION: Add weekend indicator variable
Add a variable called $isWeekend and set it to true.
PHP
Need a hint?

Use true without quotes for boolean true.

3
CORE LOGIC: Use nested if statements to check conditions
Write nested if statements to check if $weather is "sunny". Inside that, check if $time is "morning". If both are true, set a variable $message to "Good morning! Enjoy the sunny day!". Otherwise, set $message to "Have a nice day!". If $weather is not "sunny", set $message to "Stay indoors and relax.".
PHP
Need a hint?

Use == to compare strings inside if conditions.

4
OUTPUT: Print the message
Write a print statement to display the value of the variable $message.
PHP
Need a hint?

Use print($message); to show the message.