Using Return is always the way to go. Control is passed back to the calling routine as soon as return is encountered. Much more efficient. Although in your example it would not actually make much difference since it's an if-else. In other cases it would. Being explicit in your code execution paths is also good software enginering practice. So
function func($var) {
if($var) {
.. result ..
return $result;
} else {
.. a whole lot of code ..
return $other_result;
}
}
// is 'better' than
function func($var) {
if($var) {
.. result ..
$foo = $bar;
} else {
.. a whole lot of code ..
$foo = 'lamb';
}
return $foo
}
// or the even worse
function func($var) {
if($var) {
.. result ..
$_SESSION['foo'] = $bar;
} else {
.. a whole lot of code ..
$_SESSION['foo'] = 'lamb';
}
}