获取多维数组的结束值

问题描述:

我有一个未定义长度的多维数组,看起来像

I've got an multidimensional array of undefined length that looks like

Array
(
    [0] => Array
        (
            [price] => 75
        )

    [1] => Array
        (
            [price] => 90
        )

    [2] => Array
        (
            [price] => 95
        )

    [3] => Array
        (
            [price] => 130
        )

)

如何获取数组中最后一个元素的价格值?

How can I get the value of price of the last element in the array?

干杯

试试这个:$array 是你的输入数组

Try this : $array is your input array

$arr   = end($array);
echo $arr['price'];

使用 PHP 5.4 或更新版本:end($array)['price'] – fab (fab 评论)

EDIT : And with PHP 5.4 or newer: end($array)['price'] – fab (Comment by fab)