Created
March 29, 2011 09:08
-
-
Save rowanmanning/892045 to your computer and use it in GitHub Desktop.
A much cleaner way of writing PHP foreach loops
This file contains hidden or 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 | |
// 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