Alex Rivera | Logout

Checking if a key is the last element in an array?

Asked 2010-02-14T11:35:24.267
10

How can I check if this key is the last element in an array?

$array = array("a","b","c");

The value "c" would have the key 2. Is there some code like this is_end(2) which returns true or false depending if they key is the last of the array? Is there some kind of while() statement I can use?

Edit
Report

1 Answer

1
$is_2_lastone = array_pop(array_keys($array)) === 2;
answered 2010-02-14T11:38:33.917

Your Answer