为了账号安全,请及时绑定邮箱和手机立即绑定

php 解析对象细节中的数组

php 解析对象细节中的数组

PHP
叮当猫咪 2022-01-02 20:03:17
我被困在我的 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 等
查看完整描述

2 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

所以,你可以迭代details如下:


foreach($your_variable->result->details as $current_detail){

   echo $current_detail->account;

   // other code here

}


查看完整回答
反对 回复 2022-01-02
?
缥缈止盈

TA贡献2041条经验 获得超4个赞

如果您转换为数组,您的数据就是对象,您可以简单地做到这一点




$array=json_decode(json_encode($data),true); 


print_r($array);


如果只有一个细节键


$array=json_decode(json_encode($data),true)



print_r($array['result']['details']);


查看完整回答
反对 回复 2022-01-02
  • 2 回答
  • 0 关注
  • 190 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信