0
Array ( 
    [Team1] => Array ( 
        [win] => 1 
        [draw] => 0 
        [lost] => 0 
    ) 
    [Team2] => Array ( 
        [win] => 1 
        [draw] => 1 
        [lost] => 1 
    ) 
    [Team3] => Array ( 
        [win] => 1 
        [draw] => 0 
        [lost] => 1 
    ) 
    [AnotherTeam] => Array ( 
        [win] => 0 
        [draw] => 0 
        [lost] => 1 
    ) 
    [LastTeam] => Array ( 
        [win] => 0 
        [draw] => 1 
        [lost] => 0 
    ) 
)

以上是生成数组的示例。想象一下,有一些足球俱乐部的胜场数和输球数。

我想将此数组打印为表格的行和列,如下所示;

Team   |  Win |  Draw  |  Lost
Team 1    1      0        0
Team 2    1      1        1

我有一个使用提取方法的建议。但是没有好好想清楚。希望任何人都可以给我一个线索。

谢谢,

4

3 回答 3

1
$teamArr=Array ('Team1' => Array ('win' => 1 ,'draw' => 0,'lost' => 0),
'Team2' => Array ('win' => 1 ,'draw' => 0,'lost' => 0) ,
'Team3' => Array ('win' => 1 ,'draw' => 0,'lost' => 0),
'Another team' => Array ('win' => 1 ,'draw' => 0,'lost' => 0),
'Last Team' => Array ('win' => 1 ,'draw' => 0,'lost' => 0));

echo '<table width=100%><tr><th>Teams</th><th>Win</th><th>Draw</th><th>Lost</th> </tr>';
foreach($teamArr as $key => $value) {

 echo "<tr> <th>$key</th>";
        foreach($value as $status) {
          echo "<th>$status</th>";
        }
 echo "</tr>";

}

echo '</table>';
于 2013-03-14T05:03:12.240 回答
0

试试这个:

echo '<table><tr><th>Teams</th><th>Win</th><th>Draw</th><th>Lost</th></tr>';
foreach($teamsArray as $key => $value) {

 echo "<tr> <td>$key</td>";
            foreach($value as $status) {
              echo "<td>$status</td>";
            }
 echo "</tr>";

}

echo '</table>';
于 2013-03-14T04:47:40.087 回答
0

试试这个 :

<table>
<tr><td>Team</td><td>Win</td><td>Draw</td><td>Lost</td></tr>
<?php foreach($your_array as $key=>$val){ ?>
<tr><td><?php echo $key;?></td><td><?php echo $val['win'];?></td><td><?php echo $val['draw'];?></td><td><?php echo $val['lost'];?></td></tr>
<?php } ?>
</table>
于 2013-03-14T07:49:03.990 回答