In PHP, if nothing is done in a function and the end is reached it will be as if it returns false. Because of this it's never necessary to return false if nothing else is to be executed inside the function. This leaves us with this:
function test($val = 'a') {
if($val == 'a') {
return true;
}
}
If there is only one command after an if, elseif or else statement, the braces ("{" "}") aren't necessary, which make us end up with this:
function test($val = 'a') {
if($val == 'a') return true;
}
In PHP you can actually return a comparison, which will be executed right before it's returned. This is what some of the others who answered this post suggested. Doing this leave us with this code:
function test($val = 'a') {
return ($val == 'a');
}
True will be returned if the block "($val == 'a')" is true, otherwise false will be returned, since it's not true. Logic.
I actually tend to use the second convention I presented, just out of habit. Seeing the beauty of the simplicity of the third one presented by the others I will probably switch to that when applicable.
EDIT:
If you want to write code that is easier for non-PHP experts to understand, another alternative might be the following:
function test($val = 'a') {
if($val == 'a')
return true;
else
return false;
}
I'd say that not using the braces in the circumstances as described in my second example gives you easier-to-read code, since the braces tend to make your code look messy if they don't contain multiple rows.