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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵