Get last key-value pair in PHP array

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

I have an array that is structured like this:

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

[34] => Array
    (         


        
9条回答
  •  梦毁少年i
    2020-12-29 01:49

    Another solution cold be:

    $value = $arr[count($arr) - 1];
    

    The above will count the amount of array values, substract 1 and then return the value.

    Note: This can only be used if your array keys are numeric.

提交回复
热议问题