if statement

I always seem to forget how the short if statement is working in PHP so here it is for a future reference.

Normally you should write it like this in code

if(a == b){ echo “a”; }else{echo “b”;}

There is also a possibility to write this much faster like so:

(a == b) ? echo “a” : echo “b”; 

Isn’t that a lot easier.

To be completely correct don’t use {} in the template files. You might rather use something like this:

if(a==b):
echo “a”;
else:
echo “b”;
endif;

Same for foreach where you will use foreach(): and endforeach;

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">