PHP boolean values - shorter and semantic IFs

This is a simple one but I am all for making code neater, tidier and more readable.

If you are using a boolean value for evaluating an IF statement, you would typically:

$valid = true;
if ($valid == true)
{
# do something
}
else
{
# do something else
}

A shorter and more readable (try saying it out loud in pseudo code) method would be:

if ($valid)
{
# do something
}
And to test for false:

if (!$valid)
{
# do something
}
A basic one, but I find the little touches make a big difference.

Are you a Developer, Designer or Copy Writer? Or Looking For One?

Click here to see 100s of jobs updated every day that you can complete to earn good money. Also find that programmer, designer or copy writer you have been looking for - advertise and get the best guy for your job - click here to find out more

Leave a Reply

Make $100,000/Month - Every Month!

It Works! We Make Our Customers Millionaires! Act now and get $600 bonus and a Free Money Making Website! - click to get started