php-在Do中按列分组。。循环时

php-在Do中按列分组。。循环时,php,loops,while-loop,Php,Loops,While Loop,我知道这是非常基本的。。。但不幸的是,我现在可以用我的头来做,而且这不是我的家庭作业这是我申请时需要的合乎逻辑的,我的人告诉了我线索。。。这是我的代码 <?php $i = 0; $header = 0; $hitungLoopingObat= 9; do{ $remainder = ($i+1) % 5; $head = ($remainder+$i) % 5; // output: 1 .. 1 // $head = (1+$remainder) % 5; // outpu

我知道这是非常基本的。。。但不幸的是,我现在可以用我的头来做,而且这不是我的家庭作业这是我申请时需要的合乎逻辑的,我的人告诉了我线索。。。这是我的代码

<?php
$i = 0;
$header = 0;
$hitungLoopingObat= 9;
do{
  $remainder = ($i+1) % 5;
  $head = ($remainder+$i) % 5; // output: 1 .. 1
  // $head = (1+$remainder) % 5; // output: 2 .. 2
  // $head = (1+$header) % $hitungLoopingObat; // output: 1 .. 6

  if($remainder == 1)
    echo "Header " .$head. "\n";

  echo "Konten Ke " . $i . "\n";
  if( $remainder == 0) {
    echo "new line \n";
  }
  $i++;
  $header++;
}
while($i <= $hitungLoopingObat || $header <= $hitungLoopingObat);
if($remainder > 0){
  $loncat = (5 - $remainder)+1;
  for($j=0; $j<$loncat; $j++)
  {
    echo "Sisa New Line " .$loncat. "\n";
  }
}

您有一个名为
$header
的变量,该变量似乎实际上未被使用(它的值与
$i
的值完全相同),您不妨让它做些什么。去掉循环末尾的
$header++
,这一行:

$head = ($remainder+$i) % 5;
while($i <= $hitungLoopingObat || $header <= $hitungLoopingObat);
并更改此代码:

if($remainder == 1)
    echo "Header " .$head. "\n";
致:

现在,考虑到
$i
$header
在循环中所做的事情完全相同,不清楚您是否希望在
$i>$hitungLoopingObat
$header>$hitungLoopingObat
或两者中终止。因此,由于此更改会影响
$header
的行为,您可能需要更改此行:

$head = ($remainder+$i) % 5;
while($i <= $hitungLoopingObat || $header <= $hitungLoopingObat);

while($i Yes,i missing..这个逻辑循环!谢谢先生..这个链接现在可以使用..顺便说一句,如果页眉停止增加,最后一行停止打印“新行”如何..我使用$hitungLoopingObat=9示例..我希望你给我线索先生…谢谢。请看我的编辑。这应该可以解决“新行”问题问题。如果它解决了问题,请将答案标记为已接受,以便其他用户可以找到。谢谢。我无法接受我是stackoverflow中发布的新手。
do {
  $remainder = ($i+1) % 5;

  if($remainder == 1)
    echo "Header " . $header++ . "\n";

  echo "Konten Ke " . $i . "\n";
  if( $remainder == 0 && $i < $hitungLoopingObat) {
    echo "new line \n";
  }
  $i++;
}
while ($i <= $hitungLoopingObat);