0
0
PHPprogramming~15 mins

If-else execution flow in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else execution flow
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Build a PHP program that uses if-else statements to decide if a person can vote based on their age.
📋 What You'll Learn
Create a variable called age with a specific value.
Create a variable called voting_age set to 18.
Use an if-else statement to check if age is greater than or equal to voting_age.
Print "You can vote." if the person is old enough.
Print "You cannot vote yet." if the person is too young.
💡 Why This Matters
🌍 Real World
Checking age eligibility is common in websites for voting, driving licenses, or age-restricted content.
💼 Career
Understanding if-else logic is fundamental for programming jobs that require decision making and flow control.
Progress0 / 4 steps
1
Create the age variable
Create a variable called age and set it to 20.
PHP
Need a hint?

Use $age = 20; to create the variable.

2
Set the voting age
Create a variable called voting_age and set it to 18.
PHP
Need a hint?

Use $voting_age = 18; to create the variable.

3
Write the if-else statement
Write an if statement that checks if $age is greater than or equal to $voting_age. If true, print "You can vote.". Otherwise, print "You cannot vote yet.".
PHP
Need a hint?

Use if ($age >= $voting_age) { ... } else { ... } and print() inside.

4
Display the result
Run the program and print the output to show if the person can vote or not.
PHP
Need a hint?

The program already prints the result. Just run it to see the output.