Last in array?
Posted: Sun Aug 23, 2009 4:09 pm
When looping through an associative array, is there a way to find out if it's the last item in the array?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$lastkey = end(array_keys($arr));
foreach ($arr as $key => $value) {
if ($key == $lastkey) {
...
}
}