Php 垂直打印数字并将其分组

Php 垂直打印数字并将其分组,php,Php,我试图打印垂直的数字,它必须在组中 这是我的密码 $nums = 105; $rows = 8; $col = floor($nums / $rows); $group = floor($col / 3); $count = 0; for ($g = 0; $g <= $group; $g++) { echo "<div class='group'>"; for ($i = 1; $i <= $rows; $i++) { for ($j =

我试图打印垂直的数字,它必须在组中

这是我的密码

$nums = 105;
$rows = 8;
$col = floor($nums / $rows);
$group = floor($col / 3);
$count = 0;
for ($g = 0; $g <= $group; $g++) {
    echo "<div class='group'>";
    for ($i = 1; $i <= $rows; $i++) {
        for ($j = $i; $j <= 24; $j = $j + $rows) {
            $count++;
            if($count>$nums){
                break;
        }
            echo "<div class='fleft'>$count</div>";
        }
        echo "<div class='clear'></div>";
    }
    echo "</div>";
}
$nums=105;
$rows=8;
$col=楼层($nums/$rows);
$group=楼层($col/3);
$count=0;
对于($g=0;$g
for($group=0;$group<3;$group++){

因为($row=1;$row可能是我疯了,做了一个简单的改变……试试这个

$nums = 105;
$rows = 8;
$col = floor($nums / $rows);
$group = floor($col / 3);
$count = 0;
$letCounter=0;  //added a counter

for ($g = 0; $g <= $group; $g++) {

    echo "<div class='group'>";
    for ($i = 1; $i <= $rows; $i++) {
        $letCounter=0; //reset counter on each loop
        for ($j = $i; $j <= 24; $j = $j + $rows) 
        {
         $count++;
         if($count>$nums)
         {break;}
        //made an alter  in the below line , some math :)
         echo "<div class='fleft'>".($letCounter++ * $rows +$i)."</div>";  
        }
        echo "<div class='clear'></div>";
    }
    echo "</div>";
}
$nums=105;
$rows=8;
$col=楼层($nums/$rows);
$group=楼层($col/3);
$count=0;
$letCounter=0;//添加了一个计数器
对于($g=0;$g这可能有效

$nums = 105;
$rows = 8;
$col = floor($nums / $rows);
$group = floor($col / 3);
$count = 0;
$flag = true;
for($c=1;$c<=$col;$c++)
{

        if($c%$group== 1)
        {
            echo "Group Start";
            $flag = false;
        }
        for ($i = 1; $i <= $rows; $i++) {
                $count++;
                echo "<div class='fleft'>$count</div>";

            echo "<div class='clear'></div>";

        }
        echo "Line End";
        if($c%$group == 2&& $flag)// Check here for your requirement        
            echo "Group End </br>";
        $flag = true;

}
$nums=105;
$rows=8;
$col=楼层($nums/$rows);
$group=楼层($col/3);
$count=0;
$flag=true;
对于($c=1;$c
$nums=105;
$rows=8;
$colsize=3;
$col=楼层($nums/$rows);
$group=地板($col/$colsize);
$count=0;
$groupsize=$rows*$colsize;

对于($g=0;$g可能会有帮助如果我只能在一个组中显示,但不能在组中显示,我可以这样做。我希望这可以帮助您:我通过更改您的代码制作了一个解决方案。希望有帮助…发布。这不是打印到数字(105)此代码无法准确打印您想要的数字。您需要根据需要更改代码。我已经为您提供了以8*3为一组打印数字的逻辑。问题是:put$nums=31,缺少30,它应该打印到31。这是打印到32。顺便说一句,这很好。我投了赞成票logic@BhavikPatel是的……有什么问题吗第1 9 17 2 10 18 3 11 19 4 12 20 5 13 21 6 14 22 7 15 23 8 16 24 1 9 17 2 10 18 3 11它在24小时后重复不增加
$nums = 105;
$rows = 8;
$col = floor($nums / $rows);
$group = floor($col / 3);
$count = 0;
$flag = true;
for($c=1;$c<=$col;$c++)
{

        if($c%$group== 1)
        {
            echo "Group Start";
            $flag = false;
        }
        for ($i = 1; $i <= $rows; $i++) {
                $count++;
                echo "<div class='fleft'>$count</div>";

            echo "<div class='clear'></div>";

        }
        echo "Line End";
        if($c%$group == 2&& $flag)// Check here for your requirement        
            echo "Group End </br>";
        $flag = true;

}
$nums = 105;
$rows = 8;
$colsize = 3;

$col = floor($nums / $rows);
$group = floor($col / $colsize);
$count = 0;
$groupsize = $rows * $colsize;
for ($g = 0; $g <= $group; $g++) {
    echo "<div class='group'>";

    $modulo = 0;
    $correction = 0;
    $rest = $nums - $count;
    if ($rest < $groupsize) {
        $empty = $groupsize - $rest;
        $correction = floor($empty / $colsize);
        $modulo = $empty % $colsize;
    }
    for ($i = 1; $i <= $rows; $i++) {
        $colind = 0;
        for ($j = $i; $j <= $groupsize; $j = $j + $rows) { 
            $count++;
            if ($count > $nums) {
                break;
            }
            $val = $j + ($g * $groupsize);

            $val -= $colind * $correction;
            $modcor = $colind - ($colsize - $modulo);
            if ( $modcor > 0 ) {
                $val -= $modcor;
            }
            echo "<div class='fleft'>" . $val . "</div>";
            $colind++;
        }
        echo "<div class='clear'></div>";
    }
    echo "</div>";
}