Get last key-value pair in PHP array

前端 未结 9 723
别那么骄傲
别那么骄傲 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:00

    $last = array_slice($array, -1, 1, true);
    

    See http://php.net/array_slice for details on what the arguments mean.

    P.S. Unlike the other answers, this one actually does what you want. :-)

提交回复
热议问题