Branching with if and else in PHP is straightforward.
To run the program, save it as if_else.php and use the PHP CLI:
Note that you don’t need parentheses around conditions in PHP for if statements, but they are commonly used for clarity. The curly braces {} are required if you have more than one statement in a block.
PHP does have a ternary operator, which provides a shorthand way of writing simple if-else statements:
This can be useful for simple conditions, but for more complex logic, a full if statement is often more readable.