Wed 21 Nov 2007
1. http://www.php.net/manual/en/control-structures.alternative-syntax.php shows an alternative syntax for loops:
foreach($list as $item)
{
echo $item;
}
can be done as:
foreach($list as $item):
echo $item;
endforeach
2. if your server has short tags enabled, you can do this:
<? $somevar="hello"; ?> <?=$somevar?>
The syntax of #1 is actually a carry over from earlier versions of PHP. Specifically, PHP 2, which was called PHP/FI (PHP/Form Interpreter) used this syntax.
As an interesting side note, if you examine a compiled smarty template, you might notice this same syntax.
Also, short tags can occasionally do things you don’t expect. For example, if a file with a php-processed extension happens to contain an xml header:
You now have a syntax error.