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):
[code=php]stdClass Object (
[return] => Array (
[0] => stdClass Object (
[individualWinePageURL] =>
[previousTradePercentage] => 6.6364
[region] => bdxr
[tradePrice] => 1100
[transactionDate] => 2012-10-17T00:00:00.000+01:00
[unitSize] => 12x75cl
[vintage] => 1988
[wineCode] => 144
[wineName] => Lynch Bages )
[1] => stdClass Object (
[individualWinePageURL] =>
[previousTradePercentage] => 4.3478
[region] => rho
[tradePrice] => 575
[transactionDate] => 2012-10-16T00:00:00.000+01:00
[unitSize] => 12x75cl
[vintage] => 2010
[wineCode] => 317466
[wineName] => Clos Papes, CNDP )
[2] => stdClass Object (
[individualWinePageURL] =>
[previousTradePercentage] => -1.0417
[region] => bdxr
[tradePrice] => 4800
[transactionDate] => 2012-10-16T00:00:00.000+01:00
[unitSize] => 12x75cl
[vintage] => 2004
[wineCode] => 622
[wineName] => Lafite Rothschild
) ) )
I’ve tried various kinds of loops but none of them work. Like for example (after loading the object to $results):
[code=php]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)