Skip to content

Instantly share code, notes, and snippets.

@timw4mail
Created October 9, 2013 18:24
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 timw4mail/6905820 to your computer and use it in GitHub Desktop.
Save timw4mail/6905820 to your computer and use it in GitHub Desktop.
Loops and references
<?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