如何在magento中从数组中获取单个对象值


how to get single object value from array in magento?

我正在尝试计算运费,并从REST API获得响应。我想从响应数组中返回"delivery_charges"的值吗?

Array
(
[response] => Array
    (
        [delivery_charges] => 41
        [return_charges] => 83
        [all_charges] => Array
            (
                [DL] => 32
                [FS] => 30
                [DTO] => 0
                [RTO] => 32
                [ST] => 14.5
                [COD] => 0
                [TDS] => 0
                [CARD] => 0
                [CNC] => 0
            )
        [canc_charges] => 0
        [pickup_charges] => 0
        [params] => Array
            (
                [md] => E
                [pt] => prepaid
                [cl] => xxxxxxx
                [o_pin] => 560076
                [d_pin] => 560062
                [token] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                [gm] => 100
                [d_city] => Bangalore
                [o_city] => Bangalore
            )
    )

)

我只使用就得到了答案

return $shipping_charge['response']['delivery_charges'];

您只需在末尾添加以下内容。如果$shipping_charge是数组,则写入:

return $shipping_charge['response']['delivery_charges'];