如何在Opencart中获取多维数组的最后一个数组值

时间:2017-12-22 05:54:20

标签: php arrays multidimensional-array opencart

我正在使用Opencart框架,并且我定制了Opencart移动API。问题是我得到了这样的数组

Array (
    [0] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 20
        [option_id] => 13
        [option_value_id] => 49
        [price] => 280.0000
        [value] => 1000.00000000
        [name] => please select weight
        [type] => select
        )
    ) 
Array (
    [0] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 20
        [option_id] => 13
        [option_value_id] => 49
        [price] => 280.0000
        [value] => 1000.00000000
        [name] => please select weight
        [type] => select
        )
    [1] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 21
        [option_id] => 13
        [option_value_id] => 50
        [price] => 140.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )
    ) 
Array (
    [0] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 20
        [option_id] => 13
        [option_value_id] => 49
        [price] => 280.0000
        [value] => 1000.00000000
        [name] => please select weight
        [type] => select
        )
    [1] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 21
        [option_id] => 13
        [option_value_id] => 50
        [price] => 140.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )
    ) 
Array (
    [0] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 20
        [option_id] => 13
        [option_value_id] => 49
        [price] => 280.0000
        [value] => 1000.00000000
        [name] => please select weight
        [type] => select
        )
    [1] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 21
        [option_id] => 13
        [option_value_id] => 50
        [price] => 140.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )
    [2] => Array (
        [product_option_id] => 232
        [product_option_value_id] => 32
        [option_id] => 13
        [option_value_id] => 50
        [price] => 25.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )

所以,我想得到最后一个或最后一个数组值,

在给定的数组列表中,这必须是我的最终数组

Array (
    [0] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 20
        [option_id] => 13
        [option_value_id] => 49
        [price] => 280.0000
        [value] => 1000.00000000
        [name] => please select weight
        [type] => select
        )
    [1] => Array (
        [product_option_id] => 228
        [product_option_value_id] => 21
        [option_id] => 13
        [option_value_id] => 50
        [price] => 140.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )
    [2] => Array (
        [product_option_id] => 232
        [product_option_value_id] => 32
        [option_id] => 13
        [option_value_id] => 50
        [price] => 25.0000
        [value] => 500.00000000
        [name] => please select weight
        [type] => select
        )
    )

有人帮我解决了这个问题。

1 个答案:

答案 0 :(得分:3)

制作它的方法很多,但可能会有一些不同。

end($array)$array[count($array) -1]保持原始数组不变。

array_pop($array)将删除原始数组中的最后一个元素。