Conditional Statements
In a conditional statement you instruct PHP to take different actions depending on the outcome of a test. For example, you might want PHP to check whether a variable is greater than 10 and, if so, print a message. This is all done with the if statement, which looks like this:
if (your condition) { // action to take if condition is true} else { // optional action to take otherwise}
The your condition part can be filled with any number of conditions you want PHP to evaluate, and this is where the comparison operators come into their own. For example:
if ($i > 10) { echo "11 or higher";} else { echo "10 or lower";}
PHP looks at the condition and compares $i to 10. If it is greater than 10, it replaces the whole operation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access