数组中的stdClass Object如何访问

使用print_r($data)输出结果为

Array
(
    [0] => stdClass Object
        (
            [color_item_no] => 1
            [color_name] => sdf
            [size_item_no] => 1
            [size] => S
            [jar_no] => 45
            [qty] => 45
            [stand_wgt] => 
            [qty_unit] => 1
        )

    [1] => stdClass Object
        (
            [color_item_no] => 1
            [color_name] => sdf
            [size_item_no] => 2
            [size] => M
            [jar_no] => 45
            [qty] => 45
            [stand_wgt] => 
            [qty_unit] => 1
        )
)

 这种情况下一般使用任何框架原本的输出方法可能都会出错,比如laravel框架中 echo $data[0]['qty'];会报stdClass Object这个问题,那么这个时候就$data[0]->qty就可以了。

原文地址:https://www.cnblogs.com/wxy0126/p/10615586.html