I've got an array (provided by an api), of which I try to get the ID form an establishment.
I put the result in a $decodeArray = json_decode($result);
and that I put that result in a var_dump();
Which returns:
object(stdClass)#1 (2) {
["ok"]=>
bool(true)
["establishments"]=>
array(4) {
[0]=>
object(stdClass)#2 (2) {
["level"]=>
string(5) "admin"
["establishment"]=>
object(stdClass)#3 (5) {
["id"]=>
string(36) "0b246874-2c53-11e8-8fb6-001a4aa8ea16"
["name"]=>
string(9) "robinsons"
["address"]=>
string(24) "Belfast northern ireland"
["lat"]=>
float(54.594869)
["lng"]=>
float(-5.933954)
}
}
[1]=>
object(stdClass)#4 (2) {
["level"]=>
string(5) "admin"
["establishment"]=>
object(stdClass)#5 (5) {
["id"]=>
string(36) "1e95af3a-2ce7-11e8-8fb6-001a4aa8ea16"
["name"]=>
string(7) "reimink"
["address"]=>
string(13) "dorpsstraat 6"
["lat"]=>
float(123.123)
["lng"]=>
float(-74.99)
}
}
[2]=>
object(stdClass)#6 (2) {
["level"]=>
string(5) "admin"
["establishment"]=>
object(stdClass)#7 (5) {
["id"]=>
string(36) "3d1e500b-2c4d-11e8-8fb6-001a4aa8ea16"
["name"]=>
string(14) "kelly's cellar"
["address"]=>
string(24) "Belfast northern ireland"
["lat"]=>
float(54.599508)
["lng"]=>
float(-5.93216)
}
}
[3]=>
object(stdClass)#8 (2) {
["level"]=>
string(5) "admin"
["establishment"]=>
object(stdClass)#9 (5) {
["id"]=>
string(36) "75987f56-2de4-11e8-8fb6-001a4aa8ea16"
["name"]=>
string(7) "reimink"
["address"]=>
string(12) "graslanden 2"
["lat"]=>
float(3456.33)
["lng"]=>
int(-1)
}
}
}
}
I try to echo all the items like the 'id' and 'name' from every establishment. I tried reaching the values, but can't quite seem to get it right.
foreach ($decodeArray as $item => $key)
{
echo $item['establishments'][0]['establishment']['name'];
}
The above foreach loop seems to be the closest I can get, but it only returns "oe" (no clue where that originates from).
Thanks in advance!