PHP数组stdClass对象多维 - 回声值

时间:2015-07-08 14:32:26

标签: php arrays multidimensional-array

我有这个数组

Array (
[0] => stdClass Object
    (

        [field_commerce_total] => Array
            (
                [0] => Array
                    (
                        [rendered] => Array
                            (
                                [#markup] => 64.00  HRK
                                [#access] => 1
                            )

                        [raw] => Array
                            (
                                [amount] => 6400
                                [currency_code] => HRK
                                [data] => Array
                                    (
                                        [components] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [name] => base_price
                                                        [price] => Array
                                                            (
                                                                [amount] => 5120
                                                                [currency_code] => HRK
                                                                [data] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [included] => 1
                                                    )

                                                [1] => Array
                                                    (
                                                        [name] => tax|sample_french_vat_tax
                                                        [price] => Array
                                                            (
                                                                [amount] => 1280
                                                                [currency_code] => HRK
                                                                [data] => Array
                                                                    (
                                                                        [tax_rate] => Array
                                                                            (
                                                                                [name] => sample_french_vat_tax
                                                                                [display_title] => Croatia VAT (PDV) 25%
                                                                                [description] => 
                                                                                [rate] => 0.25
                                                                                [type] => vat
                                                                                [rules_component] => commerce_tax_rate_sample_french_vat_tax
                                                                                [default_rules_component] => 1
                                                                                [price_component] => tax|sample_french_vat_tax
                                                                                [calculation_callback] => commerce_tax_rate_calculate
                                                                                [module] => commerce_tax_ui
                                                                                [title] => Croatia VAT (PDV) 25%
                                                                                [admin_list] => 1
                                                                            )

                                                                    )

                                                            )

                                                        [included] => 1
                                                    )

                                            )

                                        [include_tax] => sample_french_vat_tax
                                    )

                            )

                    )

            )

    )
)

这个数组结构来自print_r($ results);来自drupal view global:PHP。我需要检索总金额的值,以便它可以转换为其他货币 我试图达到像这样的单一值

echo $results[0]->$field_commerce_total[0]->raw->amount;

它不起作用。安迪想到我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

更深field_commerce_total他们是数组而不是对象

echo $results[0]->field_commerce_total[0]['raw']['amount'];