Created
June 29, 2012 09:03
-
-
Save madfriend/3016812 to your computer and use it in GitHub Desktop.
PHP foreach fun
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
<?php | |
// How can foreach be implemented with while? | |
while (list($key, $value) = each($array)) { | |
print "$key is $value".PHP_EOL; | |
} | |
// How to get rid of @ in foreach (@$arr .. ) ? | |
// (this is always a bad practice, but anyway) | |
foreach (($array?:array()) as $k=>$v) { | |
print "$key is $value".PHP_EOL; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment