array_pop() with Key
try
end($array); //pointer to end
each($array); //get pair
Check out array_slice()
http://php.net/manual/en/function.array-slice.php
Last argument true
is to preserve keys.
When you pass the offset as negative, it starts from the end. It's a nice trick to get last elements without counting the total.
$array = [
"a" => 1,
"b" => 2,
"c" => 3,
];
$lastElementWithKey = array_slice($array, -1, 1, true);
print_r($lastElementWithKey);
Outputs:
Array
(
[c] => 3
)