Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表列的循环_Php_Loops - Fatal编程技术网

Php 表列的循环

Php 表列的循环,php,loops,Php,Loops,我有一张简单的桌子,上面有办公清单,每个桌子有3个选项。 我需要的是一个简单的循环,将相同的名称添加到不同office行中的每个单元格。我我尝试通过php循环它,但我对它很陌生,所以它按数字顺序编号,不区分行: <tr> <td name="1"></td> <td name="1"></td> <td name="1"></td> <td name="1"></td> &

我有一张简单的桌子,上面有办公清单,每个桌子有3个选项。 我需要的是一个简单的循环,将相同的名称添加到不同office行中的每个单元格。我我尝试通过php循环它,但我对它很陌生,所以它按数字顺序编号,不区分行:

<tr>
  <td name="1"></td>
  <td name="1"></td>
  <td name="1"></td>
  <td name="1"></td>
</tr>
<tr>
  <td name="2"></td>
  <td name="2"></td>
  <td name="2"></td>
  <td name="2"></td>
</tr>
<tr>
  <td name="3"></td>
  <td name="3"></td>
  <td name="3"></td>
  <td name="3"></td>
</tr>
and so on

等等

您的php代码应该如下所示

对于($i=0;$i使用以下代码:-

echo '<table>';  // Table start
for($i=1;$i<4;$i++){                      
   echo '<tr>';   // tr start                  
     for($j=0;$j<4;$j++){
        echo "<td name='$i'></td>";   // print td
      }           
   echo '</tr>';  // tr end
}
echo '</table>'; // Table end
echo';//表开始

对于($i=1;$i您需要像这样将所有表数据保存在数组中

$data_table = array(
    array(cell_11, cell_12, cell_13, cell_14),
    array(cell_21, cell_22, cell_23, cell_24),
    array(cell_31, cell_32, cell_33, cell_34),
    array(cell_41, cell_42, cell_43, cell_44),
);
并在模板中使用两个循环:

foreach ($data_table as $row) {
    echo '<tr>';
        foreach($row as $cell) {
            echo '<td>' . $cell . '</td>';
        }
    echo '</td>';
}
foreach($data\u表为$row){
回声';
foreach($行作为$单元格){
回声“.$cell.”;
}
回声';
}

但是要小心,你需要注意数组的正确大小。

请添加完整的源代码。使用($i=0;$i)的循环内部循环是我的答案,我无法从手机中输入。你想要上述HTML的循环吗?