Skip to content

Instantly share code, notes, and snippets.

@noelmcavoy
Created March 4, 2013 22:59
Show Gist options
  • Save noelmcavoy/5086444 to your computer and use it in GitHub Desktop.
Save noelmcavoy/5086444 to your computer and use it in GitHub Desktop.
Retain previous foreach value
$previous = null;
foreach($arr as $ar) {
echo $ar;
if ($previous) {
echo $previous;
}
$previous = $ar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment