dongpin1059 2015-12-01 05:21
浏览 7
已采纳

如何从PHP中的数组中读取参数?

please help me for read a parameter from array in php: when use from print_r for view array , result is:

getUserServicesResponse Object ( 
[getUserServiceResponse] => 
[return] => stdClass Object ( 
    [isactive] => 1 
    [lastQnum] => 0 
    [qnum] => 5 
    [score] => 0 
    [service] => stdClass Object ( 
        [countActive] => 73657 
        [countAll] => 199784 
        [lastTime] => 2015-12-01T08:38:06.065+03:30 
        [maxScore] => 33000 
        [minScore] => 0 
        [minregdate] => 2014-08-05T15:27:12+04:30 
        [serviceName] => game 
        [topNumber] => 09121153321 
    ) 
    [serviceID] => 12946 
    )
)

i want print serviceName value from array that is game or print score from array that is 0 thanks

  • 写回答

2条回答 默认 最新

  • duanchi8836 2015-12-01 05:43
    关注

    To access a parameter from php object (stdClass or normal)

    you need object name with -> and the attribute name which you want to access,

    in your case there are many stdClass objects one after another so the correct ways is,

     echo $getUserServicesResponse->return->service->serviceName;
    

    output:

    game
    

    FYI

    the structure for which i have generated the output

    stdClass Object
    (
        [return] => stdClass Object
            (
                [isactive] => Harry Potter and the Prisoner of Azkaban
                [service] => stdClass Object
                    (
                        [serviceName] => game
                    )
    
            )
    
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用wpf制作打砖块游戏时遇到的一个Bug
  • ¥15 qrCodeDetector.detectAndDecode
  • ¥15 海洋可控源和大地电磁一维联合反演
  • ¥15 MFC多文档程序获取视图指针问题
  • ¥20 解体如何编写程序还有运行结果截图
  • ¥15 如何把matlabR2023遗传算法工具箱里面的各类选项对应的代码调出来呢?
  • ¥30 MDIGetActive() 获取活动view
  • ¥15 有数据,如何安装使用CLIP模型检索图片
  • ¥15 lingo代码报错无法运行,如何解决,如果能解决请提供能够运行的lingo代码
  • ¥100 读取 IMU BNO080 数据