从DB访问数据

I'm getting data from database and putting it in a variable $data. If I'll print_r($data), I'll get something like that:

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [name] => Bob
        )
    [1] => stdClass Object
        (
            [id] => 2
            [name] => Mike
        )
)

It has more [key] => value in each of them, and obviously it doesn't end on [1].

I'm using foreach() like that:

foreach ($data as $item) {
   foreach ($item as $key => $value) {
       //code
   }
}

I have two question regards all the above:

1) Is there less complex technique to get the $key and $value?

2) If, for example, I want to output only the [name], how would I access it? The $key[placeholder] while placeholder is a number is outputting the letter number value of the $key.

You have an array with object, so if you want only the name:

$name_list = array();

foreach ($data as $obj) {
    $name_list[] = $obj->name;
}

This way you will have an array with only the name of each object.

So to summarize :

You loop through an array of obj, so to access the properties of each object just do :

$obj->/* the properties */;