$array = array(
'first' => 123,
'second' => 456,
'last' => 789,
);
end($array); // move the internal pointer to the end of the array
$key = key($array); // fetches the key of the element pointed to by the internal pointer
var_dump($key);
将输出:
string 'last' (length=4)
即我数组的最后一个元素的键。
完成此操作后,数组的内部指针将位于数组的末尾。如注释中所指出的,您可能希望reset()
在数组上运行以将指针带回到数组的开头。