1

Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code

$response = $amazonEcs->category('DVD')->responseGroup('Large')->search("Matrix Revolutions");
var_dump($response);

I was using var_dump($response) and now I want to know how can I get the values of Item from 0 to 9.

enter image description here

enter image description here

Community
  • 1
  • 1
Sui Go
  • 463
  • 2
  • 12
  • 31

2 Answers2

1

Item is nested inside a couple of objects. Assuming your outer object is $response, you are looking for:

$response->Items->Item[0]

items is an object stdClass, and item is a property of that object. item itself is an array, having the keys 0-9 you are looking for.

Each of those array elements is then an object stdClass itself, so access its properties (which we can't see in your output) with the -> operator.

$response->Items->Item[0]->someProperty
$response->Items->Item[9]->someOtherProperty

Edit: Changed item to Item, as it is capitalized in the sample output.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Can I echo $response->items->item[0]? – Sui Go Oct 11 '12 at 02:28
  • I triec echoing it it says "Catchable fatal error: Object of class stdClass could not be converted to string" – Sui Go Oct 11 '12 at 02:29
  • 1
    @SuiGo Not directly, because `item[0]` is not a string. It's an object. You can `var_dump($response->items->item[0]` to see what's inside it. It has its own additional properties (like `someProperty, someOtherProperty` in my example above) which you need to access. – Michael Berkowski Oct 11 '12 at 02:29
1

Use "->" to go inside objects and use [] to go inside arrays.

So, you are looking for

  $response->items->item

Use foreach to loop :

 foreach ($response->items->item as $item)
  {

            // Process $item, which will be $item[0], $item[1].. in each iteration.
   }
janenz00
  • 3,315
  • 5
  • 28
  • 37