Which is better?
function test($val = 'a') {
if($val == 'a') {
return true;
}
return false;
}
or
function test($val = 'a') {
if($val == 'a') {
return true;
} else {
return false;
}
}
Effectively, they do the same thing. If $val isn’t ‘a’, the function returns false. Just personal preference?
I think it comes down to how the comparison “feels” to you. I’d use the first if it seemed like $val being “a” was a special case, and usually the function returned false. I’d use the second if it felt more like it was 50/50 which way it would go.