JSON FEED:
{
"Group": [
{
"name": "HolderOne",
"operators": [
{
"username": "ken",
"status": 3
},
.....etc.....
CODE:
<?php
$json = file_get_content('path to feed');
$data=json_decode($json);
echo $data->cGroup[0]->operators[0]->username; //WORKS!
if (is_array($data->Group->operators))
{ foreach($data->Group->operators as $operator)
{if($operator->username == "ken") {echo $operator->status;}}
} else { echo 'NOT AN ARRAY'; } //DOESNT WORK - DISPLAYS NOT AN ARRAY
?>
I am trying to say if the username is Ken (or whatever I specify when I code more) display the correspoding status.
So…
echo $data->Group[0]->operators[0]->username; //WORKS!
but…
foreach($data->Group->operators as $operator) {if($operator->username == "ken") {echo $operator->status;}}
…doesn’t – probably something obvious, but can anyone see my problem?
Cheers
Andy
It would have to be
$data->Group[0]->operators, or loop through theGroupsand have another loop inside…