Archive

Archive for October 17th, 2008

if statement

October 17th, 2008 van Rumste Kenneth No comments

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;

Categories: General Tags: