Reputation: 6365
function newLinks($a,$b,$c,$d,$e,&$links) {
switch ($a) {
case '00':
$links = "Under Process";
return true;
break;
case '01':
$links = "Processed";
return true;
break;
case '10':
$links = "Deleted. Under Process";
return true;
break;
case '11':
$links = "Deleted. Processed";
return true;
break;
default:
return false;
}
}
Is break needed after return true?
Because I do something like this:
if ( newLinks($a,$b,$c,$d,$e,$links) ) {
echo $links;
} else {
echo 'Failed';
}
Upvotes: 2
Views: 398
Reputation: 5055
well you can leave the breaks for clarity to separate the cases. However this can cause bigger issues in the future, because you may not notice the returns.
Why not set a variable in each case, and return once after the switch function is over? In my opinion this will make the code much clearer.
Upvotes: 2
Reputation: 2060
The return
statement will just pull it off the function. You don't need the break
statement in this case.
Upvotes: 1
Reputation: 2988
No, you won't need the break;
, as the function is not executing further after a return
call.
Upvotes: 2
Reputation: 219864
Break is unecessary in this case as the function immediately terminates after returning the value so the break statement would never be reached anyway.
Upvotes: 2