When you look at other people’s programs, you’ll likely see a lot more curly brackets than we’ve used in this tutorial. Many programmers, especially those who are familiar with C, Java, Javascript, or Perl, will use curly brackets in PHP to mark the beginning and end of conditional blocks. Instead of IF:/ENDIF they’ll use IF { }.
For example, this foreach loop should look familiar to you by now:
FOREACH ($items as $item):
echo "<li>$item</li>\n";
ENDFOREACH;
But programmers from other languages might write the same code as:
foreach ($items as $item) {
echo "<li>$item</li>\n";
}
I’ve used the former syntax throughout this tutorial because I find that it is easier--especially for beginners--to see where their conditional blocks end if the ending states what the purpose of that ending is. PHP is often interspersed with HTML. If you see “ENDWHILE;” sitting on its own at the end of some HTML, you know that this is the end of a WHILE: loop. If you see “}” at the end of some HTML, you’ll need to work to find the “{“ that it matches. It could be the end of an if, a foreach, a while, a for, or a switch.
Some text editors will let you double-click the close curly bracket to match to its opening curly bracket. But because PHP is interspersed with HTML, this doesn’t always work as well as it does in programming languages that are not embedded in HTML.