Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created March 29, 2011 09:08
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 rowanmanning/892045 to your computer and use it in GitHub Desktop.
Save rowanmanning/892045 to your computer and use it in GitHub Desktop.
A much cleaner way of writing PHP foreach loops
<?php
// I've been doing this
foreach ($array as $key => $value) {
$array[$key] = $modified_value;
}
// rather than this
foreach ($array as &$value) {
$value = $modified_value;
}
// for bloody years! You learn something new every day huh?
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment