Conditionals and Operators
Conditionals, like variables, are integral to programming and most people are familiar with them in some form or another. Dynamic Web pages, as you might imagine, frequently require the use of conditionals to alter a script’s behavior based upon set criteria.
PHP’s three primary terms for creating conditionals are if, else, and elseif.
Every conditional includes an if clause:
if (condition) { // Do something! }
This in turn can become
if (condition) { // Do something! } else { // Do something else! }
and
if (condition1) { // Do something! } elseif (condition2) { // Do something else! } else { // Do something else! }
If a condition is true, the code in the following curly braces ({}) will be executed. If not, ...
Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.