0

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 ?

3
  • What you have tried for it??? Commented Nov 6, 2015 at 12:13
  • 1
    Try $ret[3]->Course_ID Commented Nov 6, 2015 at 12:14
  • my resulted array is stored in $ret variable. so i tried $ret['Course_ID'] Commented Nov 6, 2015 at 12:15

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

if i use this means the Course_ID will printed two times. how to solve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.