Skip to content

Instantly share code, notes, and snippets.

@vienhoang
Created August 11, 2014 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vienhoang/e4c7dec93bd3e1c259ce to your computer and use it in GitHub Desktop.
Save vienhoang/e4c7dec93bd3e1c259ce to your computer and use it in GitHub Desktop.
PHP: Break out of foreach func
function limiting($num) {
$fruits = array('bananas', 'apples', 'pear');
foreach ( $fruits as $v ) {
if ( $num-- === 0) {
break;
}
echo $v . '<br />';
}
}
limiting(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment