从Json创建表格统计数据


Create table stats from Json

我有一个类似的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 }} ?>

干杯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";
}

输出

Goals, Minutes, Player
1,12,1
1,34,1