foreach with an array of stdclass objects

Posted by Jared Steffen on Stack Overflow See other posts from Stack Overflow or by Jared Steffen
Published on 2012-12-10T22:58:03Z Indexed on 2012/12/10 23:03 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

So, what I want to do is quite simple in my mind. I have an array that consists solely of four objects. I want to create a loop that will echo an attribute of each object in the array. The only success I've had, however, is echoing every object and every property of the objects. I've never dealt with objects so this is probably the TRUE root of the problem.

There's been a few revisions but the only thing I've really excelled at is creating error codes.

Here is what I have:

$categories = get_categories(array('child_of' => '8'));
foreach ($categories as $cat) {
    echo $cat->name;
};

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays