O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 according to set criteria.

PHP’s three primary terms for creating conditionals are if, else, and elseif (which can also be written as two words, else if).

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 different!

}

If a condition is true, the code in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required