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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度