Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.