访问数组中的PHP对象

时间:2017-03-15 22:38:33

标签: php

我有这个$ order对象,我想访问它shipping_name,但是,似乎无法弄明白。试过$ order-> shipping [0] [' shipping_name'] +++

更新: $ order->重量会给我3,但$ order->运费不会返回

非常感谢任何帮助

       [volume] => 0
        [weight] => 3
        [total_quantity] => 1
        [volume_unit] => m
        [weight_unit] => kg
        [shipping] => Array
            (
                [0] => stdClass Object
                    (
                        [code] => 95621
                        [shipping_currency_id] => 47
                        [countries] => DK
                        [postal_code] => 8410
                        [shipping_name] => GLS Pakkeshop - Circle K
                        [shipping_type] => gls
                        [shipping_id] => GLS - 362 - PAKKESHOP: 95621
                        [shipping_price] => 11.00000
                        [shipping_description] => 95621 Circle K Hovedgaden 74, 8410 
                        [shipping_address] => stdClass Object
                            (
                                [address_city] => Hovedgaden 74
                            )

                        [shipping_warehouse_id] => 0
                        [shipping_price_with_tax] => 11.00000
                        [shipping_price_orig_with_tax] => 
                    )

            )

2 个答案:

答案 0 :(得分:0)

我怀疑你想要$order->shipping[0]->shipping_name,因为数组中的[0]项是一个对象。

它是一个包含对象数组的对象。

答案 1 :(得分:0)

尝试$ order-> shipping [0] - > shipping_name。

如果有数组,可以使用['key']访问它。但是当你有一个对象时,你可以使用$ object-> key

访问它