Get last key-value pair in PHP array

前端 未结 9 689
别那么骄傲
别那么骄傲 2020-12-29 01:20

I have an array that is structured like this:

[33] => Array
    (
        [time] => 1285571561
        [user] => test0
    )

[34] => Array
    (         


        
9条回答
  •  既然无缘
    2020-12-29 02:09

    As the key is needed, the accepted solution doesn't work.

    This:

    end($array);
    return array(key($array) => array_pop($array));
    

    will return exactly as the example in the question.

提交回复
热议问题