我有一个像这样的Json结果
{"goals":["1","1"],"minutes":["12","34"],"player":["1","1"]}
我正在尝试创建一个包含行显示每个统计信息的表,如此
Goals Minutes Player
1 12 1
1 34 1
我目前已经编写了这些代码,虽然我得到的数据并不像我想要的那样工作。我不是那么痴迷于Json并且你可以看到它的显示。
<?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 }} ?>
干杯 强尼
答案 0 :(得分:2)
<?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";
}
<强>输出强>
Goals, Minutes, Player
1,12,1
1,34,1