douxing6434 2015-11-06 12:13
浏览 1312
已采纳

如何从php中的对象数组中获取特定的键值

I have an array like below :

Array ( [3] => 
   stdClass Object ( 
         [Course_ID] => php01 
         [Course_Type] => E 
         [Course_Name] => PHP 
         [Service] => 3L 
         [Valid_Start_Date] => 2015-11-05 
         [Valid_End_Date] => 2016-01-31 
         [Duration] => 3 
         [Re_cert_Years] => 0 
         [LMS_Course_ID] => 123 
         [id] => 3
     ) 
        [21] => 
    stdClass Object ( 
        [Course_ID] => php01 
        [Course_Type] => E 
        [Course_Name] => PHP 
        [Service] => 3L 
        [Valid_Start_Date] => 2015-11-05 
        [Valid_End_Date] => 2016-01-31 
        [Duration] => 3 
        [Re_cert_Years] => 0 
        [LMS_Course_ID] => 123 
        [id] => 21 
     ) 
  ) 

i want to get the value of Course_ID.

How to get the value from this array ?

  • 写回答

1条回答 默认 最新

  • duanqiao9541 2015-11-06 12:15
    关注

    For accessing Object key in PHP use -> operator Have you tried like following:

    foreach($ret as $index=>$obj){
        echo $obj->Course_ID;
    }
    

    It will print 2 courseID because your array of object contains 2 object. if you want to print any particular index then use this:

    echo $ret[3]->Course_ID;
    echo $ret[21]->Course_ID; //where 3 or 21 is index of array
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料