if statement

Warning! This post is either deprecated or outdated.

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:

echo “a”;
echo “b”;

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

By the way, if you found a typo, please fork and edit this post. Thank you so much! This post is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.


Fork me on GitHub