duangou1868 2017-02-17 18:08
浏览 32
已采纳

PHP访问StdClass在athor StdClass中[重复]

This question already has an answer here:

How to access to StdClass's element who is within an athor StdClass.

this is what var_dump return:

 stdClass Object
(
    [return] => stdClass Object
        (
            [barCode] => 530884HB|4320000007;502241VA|4320000008;
            [code] => 0
            [idAffiliate] => 0
            [idOrder] => 25
            [idProduct] => 320
            [message] => Résérvation effectué avec succés
            [quantity] => 2
        )

)

And I want to get the value of the [barCode]??

</div>
  • 写回答

1条回答 默认 最新

  • douka19950505 2017-02-17 18:12
    关注

    Since the property return is a public property, you could simply get the barCode like this:

    $object->return->barCode

    Example:

    $object = new StdClass();
    $object->return = new StdClass();
    $object->return->barCode = '530884HB|4320000007;502241VA|4320000008';
    

    var_dump of the object:

    object(stdClass)#1 (1) {
      ["return"]=>
      object(stdClass)#2 (1) {
        ["barCode"]=>
        string(39) "530884HB|4320000007;502241VA|4320000008"
      }
    }
    

    print_r of the object:

    stdClass Object
    (
        [return] => stdClass Object
            (
                [barCode] => 530884HB|4320000007;502241VA|4320000008
            )
    
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)