Using if...else... or just if... to determine what is returned

Posted by Nathan Loding on Stack Overflow See other posts from Stack Overflow or by Nathan Loding
Published on 2010-06-12T21:16:46Z Indexed on 2010/06/12 21:22 UTC
Read the original article Hit count: 316

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about if-statement