php结构化输出结果在foreach循环中

时间:2015-06-08 18:18:15

标签: php

我做错了什么?

查询后构建数组:

$arr = array();
while($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $arr[$r['team1']][$r['stadium']] = array($r['coach'] => $r['age']);
    $arr[$r['team2']][$r['stadium']] = array($r['coach'] => $r['age']);
}

显示数据,我如何组建团队1和团队2?例如:

<?php foreach($arr as $team => $stadiums): ?>

    <div><?php echo $team;?> AND <?php echo $team;?></div> //----- HERE I NEED PUT TEAM 1 AND TEAM 2

    <?php foreach($stadiums as $stadium => $coaches): ?>

        <?php foreach($coaches as $choach => $ages): ?>

            <?php foreach($stadiums as $stadium): ?>

                <div><?php echo $stadium;?></div>

            <?php endforeach; ?>
        <?php endforeach; ?>
    <?php endforeach; ?>
<?php endforeach; ?>

很难理解,我怎么能在一次迭代中写2 $ team =))我做错了什么?

0 个答案:

没有答案