Q:

In PHP, how can I access a child object when I don't know it's name?

Using json_decode, I've ended up with an object that looks like this:
$data->foo->bar->1234567->id
I want to access id. There are two problems, both with the number 1234567:

It's an illegal property name.
The number will differ each time, and I can't predict what the number will be. I need a way of accessing id, even when I don't know the number.

I know I can overcome problem (1) with curly braces, but I don't know how to overcome (2). I don't want to use get_object_vars, because the object is likely to be very large, and that function is very slow.
My current solution is simply
foreach ($data->foo->bar as $id); but that feels rather hacky. Is there a better way?

A:

From my comment above, using json_decode(,true) and then resetting.
The example json array looks like:
Array (
    [foo] => Array (
            [bar] => Array (
                    [1234567] => Array (
                            [id] => 1234
                        )
                )
        )
)

The code:
<?php

$data = json_decode('{"foo":{"bar":{"1234567":{"id":1234}}}}', true);

reset($data['foo']['bar']);
$number = key($data['foo']['bar']);

echo $data['foo']['bar'][$number]['id'];

Output: 1234

