If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to iterate an object

Hi - I've consumed some data from a web service and I have it in an object. I'm used to iterating arrays, but I'm having trouble seeing how this works for objects. Here is what the object look like when I do print_r() (I added some formatting for clarity):

I've tried various kinds of loops but none of them work. Like for example (after loading the object to $results):

PHP Code:

foreach ( $results as $key => $value ) {

echo $results->wineName;

}

Many variations on this as I looked for examples online as well. The thing that I'm not getting is do I have to name each level of the object? ( stdClass Object - Array - stdClass Object - Key/value?) But if I do, I don't get how to name each part. Please help! :0)

However, a better question might be to look at how you're ending up with a bunch of stdClass objects, when maybe an array would be more appropriate, such as if the data is the result of a json_decode() and you might want to set its optional 2nd parameter to true.