猿问

php 解析对象细节中的数组

我被困在我的 php 对象中解析数组


stdClass Object

(

    [result] => stdClass Object

        (

            [details] => Array

                (

                    [0] => stdClass Object

                        (

                            [account] => 

                            [address] => add1

                            [category] => receive

                            [amount] => 1100

                            [label] => 

                            [vout] => 1

                        )


                    [1] => stdClass Object

                        (

                            [account] => 

                            [address] => add2

                            [category] => receive

                            [amount] => 11600

                            [label] => 

                            [vout] => 2

                        )


                    [2] => stdClass Object

                        (

                            [account] => 

                            [address] => add3

                            [category] => receive

                            [amount] => 1000

                            [label] => 

                            [vout] => 4

                        )


                )

        ) 

)

那么我如何获取所有details索引 0,1,2 等


叮当猫咪
浏览 191回答 2
2回答

喵喵时光机

所以,你可以迭代details如下:foreach($your_variable->result->details as $current_detail){   echo $current_detail->account;   // other code here}

缥缈止盈

如果您转换为数组,您的数据就是对象,您可以简单地做到这一点$array=json_decode(json_encode($data),true); print_r($array);如果只有一个细节键$array=json_decode(json_encode($data),true)print_r($array['result']['details']);
随时随地看视频慕课网APP
我要回答