I have a Json result like so
{"goals":["1","1"],"minutes":["12","34"],"player":["1","1"]}
And i am trying to create a table with rows displaying each stat like so
Goals Minutes Player
1 12 1
1 34 1
I currently have this code written up and although i am getting teh data its not quite working the way i want it to. Im not so clued up on Json and the displaying of it as you can see.
<?php
$jsonresult = $this->item->results;
$phpArray = json_decode($jsonresult, true);
foreach ($phpArray as $key => $value) {
foreach ($value as $k => $v) {
?>
<tr><td><?php echo $v; ?></td></tr>
<?php }} ?>
Cheers Jonny
<?php
$json = '{"goals":["1","1"],"minutes":["12","34"],"player":["1","1"]}';
$array = json_decode($json,true);
print_r($array);
print "Goals, Minutes, Player\n";
foreach($array['goals'] as $key => $value) {
print $value . ','
. $array['minutes'][$key] . ','
. $array['player'][$key] . "\n";
}
Output
Goals, Minutes, Player
1,12,1
1,34,1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句