使用变量值访问嵌套 arrrray 中的值



我在访问嵌套在数组中的 stdClass 对象的值时遇到一些困难。 问题是嵌套数组值不一致,我想知道是否有办法使用某种通配符或解析路径来访问它?这是数组的输出。

Array
(
    [order_id] => 251
    [uid] => 1
    [order_status] => balance_pending
    [order_total] => 50
    [product_count] => 1
    [primary_email] => 
    [delivery_first_name] => 
    [delivery_last_name] => 
    [delivery_phone] => 
    [delivery_company] => 
    [delivery_street1] => 
    [delivery_street2] => 
    [delivery_city] => 
    [delivery_zone] => 0
    [delivery_postal_code] => 
    [delivery_country] => 840
    [billing_first_name] => 
    [billing_last_name] => 
    [billing_phone] => 
    [billing_company] => my company
    [billing_street1] => po box 678
    [billing_street2] => 
    [billing_city] => garb
    [billing_zone] => 1
    [billing_postal_code] => 95542
    [billing_country] => 840
    [payment_method] => check
    [data] => Array
        (
            [coupons] => Array
                (
                )
            [complete_sale] => logged_in
        )
    [created] => 1392066915
    [modified] => 1392066930
    [host] => 127.0.0.1
    [currency] => USD
    [products] => Array
        (
            [259] => stdClass Object
                (
                    [order_product_id] => 259
                    [order_id] => 251
                    [nid] => 71
                    [title] => attributesw
                    [model] => uuuu
                    [qty] => 1
                    [cost] => 0.00000
                    [price] => 50.00000
                    [weight] => 0
                    [weight_units] => lb
                    [data] => Array
                        (
                            [attributes] => Array
                                (
                                    [percentage] => Array
                                        (
                                            [6] => downpayment
                                        )
                                )
                            [shippable] => 0
                            [type] => new_prod
                            [module] => uc_product
                        )
                    [rdf_mapping] => Array
                        (
                        )
                    [order] => stdClass Object
                        (
                            [order_id] => 251
                            [uid] => 1
                            [order_status] => balance_pending
                            [order_total] => 50
                            [product_count] => 1
                            [primary_email] => chrysalis72@hotmail.com
                            [delivery_first_name] => 
                            [delivery_last_name] => 
                            [delivery_phone] => 
                            [delivery_company] => 
                            [delivery_street1] => 
                            [delivery_street2] => 
                            [delivery_city] => 
                            [delivery_zone] => 0
                            [delivery_postal_code] => 
                            [delivery_country] => 840
                            [billing_first_name] => 
                            [billing_last_name] =>
                            [billing_phone] => 
                            [billing_company] => 
                            [billing_street1] => 
                            [billing_street2] => 
                            [billing_city] => garb
                            [billing_zone] => 1
                            [billing_postal_code] => 95542
                            [billing_country] => 840
                            [payment_method] => check
                            [data] => Array
                                (
                                    [coupons] => Array
                                        (
                                        )
                                    [complete_sale] => logged_in
                                )
                            [created] => 1392066915
                            [modified] => 1392066930
                            [host] => 127.0.0.1
                            [currency] => USD
                            [products] => Array
 *RECURSION*
                            [quote] => Array
                                (
                                    [accessorials] => 
                                )
                            [line_items] => Array
                                (
                                    [0] => Array
                                        (
                                            [line_item_id] => subtotal
                                            [type] => subtotal
                                            [title] => Subtotal
                                            [amount] => 50
                                            [weight] => 0
                                            [data] => Array
                                                (
                                                )
                                        )
                                )
                            [rdf_mapping] => Array
                                (
                                )
                        )
                    [order_uid] => 1
                )
        )
    [quote] => Array
        (
            [accessorials] => 
        )
    [line_items] => Array
        (
            [0] => Array
                (
                    [line_item_id] => subtotal
                    [type] => subtotal
                    [title] => Subtotal
                    [amount] => 50
                    [weight] => 0
                    [data] => Array
                        (
                        )
                )
        )
    [rdf_mapping] => Array
        (
        )
)

我试图获得的值是 [nid],它在这里找到......

[products] => Array
        (
            [259] => stdClass Object
                (
                    [order_product_id] => 259
                    [order_id] => 251
                    **[nid] => 71**
                    [title] => attributesw
                    [model] => uuuu
                    [qty] => 1
                    [cost] => 0.00000
                    [price] => 50.00000
                    [weight] => 0
                    [weight_units] => lb

问题是嵌套数组的值(在本例中为 [259])总是在变化,我想知道是否有办法在不知道它所在的数组的值的情况下获取 [nid] 的嵌套值。 例如通配符。对不起,如果我的术语不合适,这不是我的专长,希望对您有意义。 非常感谢您的任何帮助!

我想通了....在阅读了我自己的问题后,我意识到我可以解析数组中的键,然后使用该键来获取值。

最新更新