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
.