Created
August 11, 2014 16:44
-
-
Save vienhoang/e4c7dec93bd3e1c259ce to your computer and use it in GitHub Desktop.
PHP: Break out of foreach func
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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