PHP数组中的动态表

PHP数组中的动态表,php,dynamic,Php,Dynamic,我正在尝试将多维php数组显示为一个表。。。有人能帮忙吗 这是我的阵列: Array ( [1] => Array ( [0] => Array ( [c1] => UA07 [s1] => 6 [c2] => Ultimate Force

我正在尝试将多维php数组显示为一个表。。。有人能帮忙吗

这是我的阵列:

Array
(
    [1] => Array
        (
            [0] => Array
                (
                    [c1] => UA07
                    [s1] => 6
                    [c2] => Ultimate Force
                    [s2] => 8
                )

            [1] => Array
                (
                    [c1] => UF HEROES
                    [s1] => 6
                    [c2] => OLD School
                    [s2] => 4
                )

            [2] => Array
                (
                    [c1] => Winners 05 
                    [s1] => not_played
                    [c2] => World XI
                    [s2] => not_played
                )

            [3] => Array
                (
                    [c1] => Outlaw
                    [s1] => 4
                    [c2] => UWK
                    [s2] => 3
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [c1] => Ultimate Force
                    [s1] => 2
                    [c2] => UF HEROES
                    [s2] => 4
                )

            [1] => Array
                (
                    [c1] => BY
                    [s1] => 0
                    [c2] => Outlaw
                    [s2] => 0
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [c1] => UF HEROES
                    [s1] => 5
                    [c2] => Outlaw
                    [s2] => 1
                )

        )

)
此阵列目前包含3发子弹,但理论上可能包含更多。。。在每一轮中,它包含每一场比赛,在每一场比赛中,它包含这些比赛的结果

C1/C2是竞争对手,S1/S2是分数

如何在列中显示每个数组,然后转到下一个数组并在列中显示它们。。把他们排成一排

任何想法都会很有帮助

我正在尝试实现如下格式:


括号

正如其他人在评论中所说,您需要一个嵌套循环。因为您没有指定表格式,所以我只创建了一个示例。你可以在


动态比赛括号:

您的阵列:

$rounds = array(
    //Round 1
    array(

        array(
            'c1' => 'UA07 ',
            's1' => 6 ,
            'c2' => 'Ultimate Force ',
            's2' => 8 ,
        ),

        array(
            'c1' => 'UF HEROES',
            's1' => 6,
            'c2' => 'OLD School',
            's2' => 4,
        ),

        array(
                'c1' => 'Winners 05 ',
                's1' => 'not_played',
                'c2' => 'World XI',
                's2' => 'not_played',
        ),

        array(
                'c1' => 'Outlaw',
                's1' => 4,
                'c2' => 'UWK',
                's2' => 3,
        ),

    ),
    //Round 2
    array(
       array(
                'c1' => 'Ultimate Force',
                's1' => 2,
                'c2' => 'UF HEROES',
                's2' => 4,
        ),

        array(
                'c1' => 'BY',
                's1' => 0,
                'c2' => 'Outlaw',
                's2' => 0,
        ),

    ),
    //Round 3
    array(
        array(
                'c1' => 'UF HEROES',
                's1' => 5,
                'c2' => 'Outlaw',
                's2' => 1,
        ),

    )
);
发电机:

$roundCount = 1;
$totalRounds = count($rounds);

echo '<table border="1"><tr>';

for($i = 1;$i <= $totalRounds;$i++)
{
    echo '<td>Round'.$i.'</td>';
}
echo '</tr><tr>';
foreach($rounds as $round)
{
    $matches = count($round);
    echo '<td>';


    foreach($round as $match)
    {

        echo $match['c1'].' - '.$match['s1'].'<br>';
        echo $match['c2'].' - '.$match['s2'].'<br><hr>';

    }
    $roundCount++;
    echo '</td>';
}

echo '</tr></table>';
结果:

发电机2:

$roundCount = 1;
$totalRounds = count($rounds);

echo '<table border="1"><tr>';

for($i = 1;$i <= $totalRounds;$i++)
{
    echo '<td>Round'.$i.'</td>';
}
echo '</tr><tr>';
foreach($rounds as $round)
{
    $matches = count($round);
    echo '<td>';


    foreach($round as $match)
    {
        echo '<table border="1">';
        echo '<tr><td>'.$match['c1'].'</td><td>'.$match['s1'].'</td></tr>';
        echo '<tr><td>'.$match['c2'].'</td><td>'.$match['s2'].'</td></tr>';
        echo '</table>';
    }
    $roundCount++;
    echo '</td>';
}

echo '</tr></table>';
带赢家的生成器:

$roundCount = 1;
$totalRounds = count($rounds);

echo '<table border="1"><tr>';

for($i = 1;$i <= $totalRounds;$i++)
{
    echo '<td>Round'.$i.'</td>';
}
echo '<td>Winner</td>';
echo '</tr><tr>';
foreach($rounds as $round)
{
    $matches = count($round);
    echo '<td>';

    if($roundCount == $totalRounds)
    {
        if($round[0]['s1'] > $round[0]['s2']) {
            $finalist = array($round[0]['c1'],$round[0]['s1']);
        } else {
            $finalist = array($round[0]['c2'],$round[0]['s2']);
        }
    }

    foreach($round as $match)
    {
        echo '<table border="1">';
        echo '<tr><td>'.$match['c1'].'</td><td>'.$match['s1'].'</td></tr>';
        echo '<tr><td>'.$match['c2'].'</td><td>'.$match['s2'].'</td></tr>';
        echo '</table>';
    }
    $roundCount++;

    echo '</td>';
}
echo '<td>';

echo '<table border="1">';
echo '<tr><td>'.$finalist[0].'</td><td>'.$finalist[1].'</td></tr>';
echo '</table>';

echo '</td>';

echo '</tr></table>';

所以使用嵌套循环?到目前为止,您尝试了什么?确实,嵌套循环和正确格式的HTML可以做到这一点,但在同一页面上显示的数据似乎很多,您可能需要使用不同的方法来处理用户友好性问题谢谢。。。我就是想不起来。。。我们以前是手工操作的,但现在变得很麻烦了。我们有一些特殊情况下,回合可能是0,但我们可以处理。。。这只是一个很好地格式化表格的例子,这样结果就像一个锦标赛括号一样排列。。再次感谢,这不太有效,我不确定如何解决。。。每个队的名字和分数都应该在各自的单元格中。。这样我们就可以很好地格式化它。。。我该怎么做?谢谢谢洛。我终于完成了这段代码的实现,遇到了一些问题。。。也许你能帮忙。当我的数组返回时,它会给我所有的比赛结果,它还会给我获胜的球队名称。。。如何将此团队名称添加到上述代码的最后一列中。。我试过一些东西,结果似乎到处都是,但我想去的地方。另外,我如何将这些列隔开,以便球队名称像在锦标赛括号中一样排列在一起?Thanks@Staggan参见我的最后一个示例。我不明白如何将这些列隔开,以便团队的名字排成一行。我已经修改了我原来的帖子,并给出了一个链接,指向我正在努力实现的目标。谢谢
$roundCount = 1;
$totalRounds = count($rounds);

echo '<table border="1"><tr>';

for($i = 1;$i <= $totalRounds;$i++)
{
    echo '<td>Round'.$i.'</td>';
}
echo '<td>Winner</td>';
echo '</tr><tr>';
foreach($rounds as $round)
{
    $matches = count($round);
    echo '<td>';

    if($roundCount == $totalRounds)
    {
        if($round[0]['s1'] > $round[0]['s2']) {
            $finalist = array($round[0]['c1'],$round[0]['s1']);
        } else {
            $finalist = array($round[0]['c2'],$round[0]['s2']);
        }
    }

    foreach($round as $match)
    {
        echo '<table border="1">';
        echo '<tr><td>'.$match['c1'].'</td><td>'.$match['s1'].'</td></tr>';
        echo '<tr><td>'.$match['c2'].'</td><td>'.$match['s2'].'</td></tr>';
        echo '</table>';
    }
    $roundCount++;

    echo '</td>';
}
echo '<td>';

echo '<table border="1">';
echo '<tr><td>'.$finalist[0].'</td><td>'.$finalist[1].'</td></tr>';
echo '</table>';

echo '</td>';

echo '</tr></table>';