Created
October 9, 2013 18:24
-
-
Save timw4mail/6905820 to your computer and use it in GitHub Desktop.
Loops and references
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 | |
// Normal foreach loop | |
foreach($foo as $bar) | |
{ | |
... | |
} | |
// Foreach with reference | |
foreach($foo as &$bar) | |
{ | |
//Modifying $bar affects the object/array you are looping over | |
} | |
// Foreach with key/value | |
foreach($foo as $bar => $baz) | |
{ | |
// Handy for when you need a numeric or associative index | |
} | |
So...you can do most anything with just foreach loops. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment