1

Struggling with this problem for an hour now and searched both stackoverflow and google and couldn't find an answer that helped. I have the following from xdebug:

 - list (array)

   -[0] (object)

     ---id  (string)

     ---proj_name  (string)

     ---proj_desc  (string)

I am trying to pull out the value of id. Can anyone tell me how to do this? Thank you.

2 Answers 2

9
$list[0]->id
  • $list is an array containing an object at position 0, therefore this object can be accessed with $list[0]
  • the object has a property named id, which can be accessed with $object->id

If you have more than one object in the array, then you can loop through the values contained in the array with foreach. For example:

foreach ($list as $object) {
    echo $object->id . "<br/>";
}

This will take each object in the array and display its id value.

Sign up to request clarification or add additional context in comments.

1 Comment

I had tried this, but the codeigniter program failed not recognizing the value when I called a controller from my form. Error elsewhere. Thanks for confirming and I am pointed in the right direction to solve now.
1

Use foreach to loop through the list:

foreach($list as $obj)    // Where $list is the list containing the objects
{
   $id = $obj->id;
}

Comments

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.