i have a json data like so
{
"code": 1,
"data": [
{
"apple": [
{
"id": 127,
"type": 1,
"color": green,
"stage": 1,
"status": 1
},
{
"id": 128,
"type": 2,
"color": red,
"stage": 1,
"status": 1
}
]
},
{
"oranges": [
{
"id":133
"type": 3,
"color": rainbow,
"stage": 1,
"status": 1
},
{
"id":134
"type": 3,
"color": black,
"stage": 1,
"status": 1
}
]
},
{
"berry": [
{
"id":4
"type": 2,
"color": white,
"stage": 1,
"status": 1
}
]
},
{
"watermelon": [
{
"id":5
"type": 2,
"color": red and blue,
"stage": 1,
"status": 1
}
]
}
],
"bleh": "Succesfully queried database"
}
i would like to create a table in php that goes somthing like this
Fruit | Type | color
apple 1 green
apple 2 red
oranges 3 rainbow
oranges 3 black
so basically what i want is when ever a object like apple has more then one array inside it the table to display apple and the corresponding data to it.
this is what i have so far
$output = json_decode(JsonData);
$result =$output['data'][0]['apple'];
<table>
<thead>
<tr>
<th>Fruits</th>
<th>Type</th>
<th>color</th>
</tr>
</thead>
<tbody>
<?php if(!isset($result)){ ?>
<tr>
<td>Empty</td>
<td>Empty</td>
<td>Empty</td>
<td>Empty</td>
</tr>
<?php else{
foreach($result as $apples){ ?>
<tr>
<td></td>
<td><?php echo "$apples["type"]";?></td>
<td><?php echo "$apples["color"]";?></td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
<?php echo "apples["type"]";?>