Created
August 4, 2016 04:42
-
-
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.
This file contains 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
/** | |
* 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