if(true):
echo 'good';
endif;
I've only see it in PHP today!
I've always been using:
if(true)
{
echo 'good';
}
if(true):
echo 'good';
endif;
I've only see it in PHP today!
I've always been using:
if(true)
{
echo 'good';
}
It is the Alternative syntax for control structures.
Quoting that page of the manual :
PHP offers an alternative syntax for some of its control structures; namely,
if
,while
,for
,foreach
, andswitch
. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:
) and the closing brace toendif;
,endwhile;
,endfor;
,endforeach;
, orendswitch;
, respectively.
I don't often see it used in "pure PHP" files, but it's quite often used when PHP is mixed with HTML in the same file -- i.e. when used as a templating language.
You can interlace the former with html very easily.
http://php.net/manual/en/control-structures.alternative-syntax.php
It's exactly the same. I often use such syntax in templates - it's much more readable then (in my opinion). Here's more: Alternative syntax for control structures
The PHP notation:
if(x=1):
dosomething();
elseif(x=2):
dosomethingelse();
andanotherthing();
else:
doesntmatcheither();
endif;
is also related to
$var=(query?true:false);
or in even more shorthand
$var=query?true:false;
But I personally don't like omitting the parenthesis; call me paranoid ;)
same effect, no diference and in my personal opinion the offer better readble code and clean syntax, also the end-like closing keyword might help in nested control structures, to indicate which one is closing instead of guessing from a bunch of braces.