In an effort to produce cleaner PHP files, I want to echo less HTML and embed more PHP. I’ve stumbled upon constructs like the following:
<?php
foreach($allOGroups as $ogroup):
if($lastGroup != $ogroup['group']):
if($lastGroup !== null):
?>
</optgroup>
<?php
endif;
?>
I’ve googled for a while now but can’t seem to find a tutorial on how to use this mysterious “:” operator. Can anyone point me in the right direction?
Thanks,
MrB
As you have discovered, the mysterious
:is simply an alternative syntax to opening and closing curly brackets. It’s most effective when you’re mingling PHP with HTML, since it makes it easier to discover whether you’re closing anif,for,foreachorwhilestructure.