O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites 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

The ? Operator

PHP offers an abbreviated version of the if statement which borrows syntax from C. It uses the question mark as a tertiary operator. Figure 3-2 outlines the format.

Figure 3-2. The ? operator.

Listing 3.3. Covering All Cases with if-elseif-else
						
							
								
							
						
					

The conditional expression is evaluated to be either true or false. If true, the expression between the question mark and the colon is executed. Otherwise, the expression after the colon is executed. The following code fragment

($clientQueue > 0) ? serveClients() : cleanUp();

does ...

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