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

如何从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 ?

图片转代码服务由CSDN问答提供 功能建议

我有一个如下数组:

  Array([  3] => 
 stdClass对象(
 [Course_ID] => php01 
 [Course_Type] => E 
 [Course_Name] => PHP 
 [服务] => 3L 
 [Valid_Start_Date  ] => 2015-11-05 
 [Valid_End_Date] => 2016-01-31 
 [持续时间] => 3 
 [Re_cert_Years] => 0 
 [LMS_Course_ID] => 123 \  n [id] => 3 
)
 [21] => 
 stdClass对象(
 [Course_ID] => php01 
 [Course_Type] => E 
 [Course_Name] =>  PHP 
 [服务] => 3L 
 [Valid_Start_Date] => 2015-11-05 
 [Valid_End_Date] => 2016-01-31 
 [持续时间] => 3 
 [Re_cert_Years]  => 0 
 [LMS_Course_ID] => 123 
 [id] => 21 
)
)
   
 
 

我想获得 Course_ID的值。

如何从中获取值 阵列?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题