Skip to content

Instantly share code, notes, and snippets.

@otkrsk
Created August 4, 2016 04:42
Show Gist options
  • Save otkrsk/70d13e530d34bbc6e73b38b3c6e33f03 to your computer and use it in GitHub Desktop.
Save otkrsk/70d13e530d34bbc6e73b38b3c6e33f03 to your computer and use it in GitHub Desktop.
A snippet of how to check for the last element of the array and perform actions on to it.
/**
* Check if the current array element is the last one, if it is, do something.
*/
$array = array('a' => 1,'b' => 2,'c' => 3);
$lastElement = end($array);
foreach($array as $k => $v) {
echo $v . '<br/>';
if($v == $lastElement) {
// This is the last element. Do as you please.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment