How to get last key in an array?

In this post will explain how to get last key in an array using php.

A solution would be using both end() and key().

end() – point array ‘s internal pointer to the last element, and returns its value.
key() – returns the index element of the current array position.

Example

<?php
$array = array('one' => 1,'two' => 2,'three' => 3);
end($array); // move the internal pointer to the end of the array
echo $key = key($array); // fetches the key of the element pointed to by the internal
?>

It prints ‘three’ in screen.

Posted in Php