Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers

up vote 5 down vote accepted
$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.

share|improve this answer
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. – TSquared Nov 5 '11 at 14:59

Use foreach to loop through the list:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.