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 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)