I have this: Array ( [0] => afprg Object ( [id:protected] => 882 ) ) ) PHP: How can I print all the id's? Thanks!
Like Einheijar mentioned, the best and the correct way is to set the variable public at declaration level or add a getter method within the object. If that isn't an option (not sure why it wouldn't) you can use reflection to get value: <?php class afprg {protected $id = 'test';} $a = array(new afprg()); print_r($a); // Similar to what you had foreach ($a as $object) { $rp = new ReflectionProperty('afprg', 'id'); $rp->setAccessible(true); echo $rp->getValue($object); } PHP:
That moment when you see lowercase named classes wrapped inside an array... that's when I know I have to unwatch the thread