O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

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

1.9. Choosing Between Alternatives

PHP allows you to test conditions and execute certain code based on the result of the test. The simplest form of this is the if statement. Listing 1.11 shows how you can customize the content of a page based on the value of a variable (see Figure 1.4).

Figure 1.4. Output from Listing 1.11.

The Today variable is set with the name of today's weekday. The if statement evaluates the expression inside the parentheses as either true or false. The == operator compares the left side to the right side. If Today contains the word Friday, the block of code surrounded by curly braces ({ and }) is executed. In all other cases ...

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