If/Else Condition Example 1: 10 is a positive number.
If/Else Condition Example 2: You are an adult.
Switch Case Example: Today is Tuesday.
Conditional statements in PHP, such as if/else and switch, allow for decision-making in the code. The if/else condition checks a statement and executes code based on whether the statement is true or false. The switch case statement is used to execute one block of code out of many based on the value of a variable. These structures help control the flow of the program by executing different code paths based on conditions.
<?php // Example 1 of if/else condition $number = 10; if ($number > 0) { echo "<p>If/Else Condition Example 1: $number is a positive number.</p>"; } else { echo "<p>If/Else Condition Example 1: $number is not a positive number.</p>"; } // Example 2 of if/else condition $age = 20; if ($age < 18) { echo "<p>If/Else Condition Example 2: You are a minor.</p>"; } elseif ($age >= 18 && $age < 65) { echo "<p>If/Else Condition Example 2: You are an adult.</p>"; } else { echo "<p>If/Else Condition Example 2: You are a senior citizen.</p>"; } // Example of switch case $day = "Tuesday"; switch ($day) { case "Monday": echo "<p>Switch Case Example: Today is Monday.</p>"; break; case "Tuesday": echo "<p>Switch Case Example: Today is Tuesday.</p>"; break; case "Wednesday": echo "<p>Switch Case Example: Today is Wednesday.</p>"; break; default: echo "<p>Switch Case Example: Today is some other day.</p>"; break; } ?>