I am trying to display JSON records. I have successfully gotten values for id, chart_id, first_name.
My issue is that values for office parameters throws error of undefined offset. How do I also print values for offices parameters?
Below is the code:
<?php
$output ='
{"previous":null,"results":[
{"id":91168488,"chart_id":"SMAM000001", "offices":[3033],"first_name":"Nancy"},
{"id":91168489,"chart_id":"MADE000004", "offices":[3044], "first_name":"Moore"}]
}
';
$json = json_decode($output, true);
foreach($json["results"] as $v1){
echo $id = $v1['id'];
echo "<br><br>";
echo $chart_id = $v1['chart_id'];
echo "<br><br>";
echo $first_name = $v1['first_name'];
echo "<br><br>";
echo $offices = $v1['offices'];
echo "<br><br>";
}
?>
$offices = implode(', ', $v1['offices']);would do it since it is an array.[3033]in"offices":[3033]makes that another array :)