When using functions, you often want to return different values depending on the result of the function. Is there any preferred method for setting a single return or setting multiple returns in a management structure? Which of these two methods is preferred?
Several declaration declarations within management structures:
function doStuff( $input ) {
if ( true === $input ) {
return 'You are an A+ fellow.';
}
else {
return 'Not too sure about you...' ;
}
}
A single return is declared, but introduced a new variable to save the result:
function doStuff( $input ) {
if ( true === $input ) {
$result = 'You are an A+ fellow.';
}
else {
$result = 'Not too sure about you...' ;
}
return $result;
}
Or is it just the case in each case?
EDIT: Wow, a lot of answers. I really understood that this could be reduced by removing another; it was more for example than anything :-).
, , " ". ! : .