tags:

views:

115

answers:

3

I have the following array called "$order" (as printed out by "print_r"):

stdClass Object
(
    [products] => Array
    (
        [0] => stdClass Object
        (
             [data] => Array
             (
                 [attributes] => Array
                 (
                     [ID] => Array
                     (
                         [0] => 57
                     )
                  )
             )
         )
    )
)

My question is, how do I reference "57"? I thought it would be something like this:

$order->products[0]->data[attributes][ID][0];

But this doesn't work. What am I missing?

+2  A: 
$order->products[0]->data['attributes']['ID'][0]
cletus
Care to share some light on why my method below and your method works?! I dont understand this at all...
RD
You're missing quotes. Sometimes they work as strings but can get messed up if ID, for example, happens to be a constant.
cletus
A: 

Nevermind. It's like this: $order->products[0]->data["attributes"]["ID"][0];

RD
+2  A: 

You're missing some quotes for the array keys. Otherwise it makes PHP think that attributes or ID is a constant (define('ID', 'foobar'); echo ID;).

$order->products[0]->data['attributes']['ID'][0];
Philippe Gerber