Skip to content

Instantly share code, notes, and snippets.

@madfriend
Created June 29, 2012 09:03
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 madfriend/3016812 to your computer and use it in GitHub Desktop.
Save madfriend/3016812 to your computer and use it in GitHub Desktop.
PHP foreach fun
<?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