[nycphp-talk] style question: returning from a function while you're in a foreach
David Mintz
david at davidmintz.org
Fri Mar 15 17:08:57 EDT 2013
function whatever(Array $array) {
foreach ($array as $key => $value) {
if ($something) {
return true;
}
}
return false;
}
Is there any reason -- style, legibility, whatever -- not to do the above?
Or should you do something like
function whatever(Array $array) {
$return = false;
foreach ($array as $key => $value) {
if ($something) {
$return = true;
break;
}
}
return $return;
}
Thanks.
--
David Mintz
http://davidmintz.org/
Fight for social equality:
http://socialequality.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20130315/c396157a/attachment.html>
More information about the talk
mailing list