PHP如何在5x5表中对数组的输出进行排序

PHP如何在5x5表中对数组的输出进行排序

本文介绍了PHP如何在5x5表中对数组的输出进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP的新手.我正在尝试在具有5行5列的5x5表格中获取游戏(名称).但是我想通过游戏的输出数量而不是预设的html表格来生成表格.我做到了,它显示游戏,但不在桌子上.您能否帮助我,并给我一个很好的解释,所以我也理解.谢谢了!

I'm very new to PHP.I am trying to get the game (names) in a 5x5 table with 5 rows and 5 cols.But i want to generate the table by the number output of games and not a preset html table.i made it work that it shows the games but not in a table.Could you please help me and give me a good explaination so i understand too.Thank's already!

 <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Merijn</title>
    </head>
    <body>
        <?php
            $games = array(
            "battlefield 1",
            "battlefield 2",
            "Out of the Park Baseball 17",
            "Overwatch",
            "Stephen's Sausage Roll",
            "Dark Souls III",
            "Kentucky Route Zero - Act IV NEW",
            "Stardew Valley",
            "Ori and the Blind Forest",
            "XCOM 2",
            "World of Warcraft: Legion",
            "Steins;Gate ",
            "The Witness",
            "Inside",
            "Hex: Shards of Fate",
            "Forza Horizon 3 ",
            "Rise of the Tomb Raider",
            "Total War: WARHAMMER",
            "Chime Sharp",
            "Pony Island",
            "F1 2016",
            "Day of the Tentacle Remastered",
            "Tales from the Borderlands",
            "DOOM",
            "Hearthstone");
            for($i =0; $i <=25; $i++){
                echo '<table rows=5 cols=5>';
                echo "<td>" . $games[$i] . "</td>" .  "<br/>";
            }
        ?>
    </body>
</html>

推荐答案

也许不是最干净的,但是它是可行的:)

Maybe not the cleanest but it works :)

<?php
$games = array(
            "battlefield 1",
            "battlefield 2",
            "Out of the Park Baseball 17",
            "Overwatch",
            "Stephen's Sausage Roll",
            "Dark Souls III",
            "Kentucky Route Zero - Act IV NEW",
            "Stardew Valley",
            "Ori and the Blind Forest",
            "XCOM 2",
            "World of Warcraft: Legion",
            "Steins;Gate ",
            "The Witness",
            "Inside",
            "Hex: Shards of Fate",
            "Forza Horizon 3 ",
            "Rise of the Tomb Raider",
            "Total War: WARHAMMER",
            "Chime Sharp",
            "Pony Island",
            "F1 2016",
            "Day of the Tentacle Remastered",
            "Tales from the Borderlands",
            "DOOM",
            "Hearthstone");
    $c = 0;
?>
<table>
<tr>
    <?php for ($i=0; $i < count( $games ); $i++) {
        if( $c == 5 )
        {
          $c = 0;
            ?>
                </tr>
                <tr>

        <?php } echo "<td>".$games[ $i ]."</td>"; $c++;
    } ?>
    </tr>

</table>

这篇关于PHP如何在5x5表中对数组的输出进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:13