PHP also has some alternative syntax for if, while, for, foreach, and switch statements. In each case, the form of the alternate syntax changes the opening curly brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. Here's an example showing an if statement using alternate syntax: <?php $value = 10; if ($value == 1): echo "\$value holds 1"; elseif ($value == 10): echo "\$value holds 10."; else: echo "\$value does not hold 1 or 10."; endif; ?> This example echoes: "$value holds 10.". Here's an example of using a for loop and alternate syntax: <?php for ($loop_counter = 0; $loop_counter < 5; $loop_counter++) : echo "I'm going to do this five times.<BR>"; endfor; ?> That's it; now that we've got operators and loops under our belts, we're ready to tackle the next stepworking with strings and arrays, coming up next in Chapter 3. |