Table - 使用 PHP 循环的垂直编号
Table - vertical numbering using PHP for cycle
我需要在 PHP 中进行一些 "for" 循环,这将生成带有垂直编号单元格的 table。为了更好地理解,这是图像:
我相信你正在努力实现这样的目标
<?php
$x = 0;
echo "<table >";
echo "<tr>";
for($x=1; $x<13; $x++){
echo "<td>$x</td>";
if($x%4 == 0 ){
echo "<tr>"."\n";
}
}
echo "</tr></table>";
?>
祝你好运!
这是您要查找的代码:
<?php
$col = 4; //number of desired columns
$row = 5; //number of desired rows
echo "<table>\n";
for($i = 1; $i<$row+1; $i++)
{
echo "<tr>\n";
for($c = 0; $c<$col; $c++)
{
echo "<td>".($i + ($c*$row))."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n"
?>
这样就可以了:
<?php
echo "<table>";
echo "<tr>";
function x($y){
return ($y<=1)?array($y):array_merge(x($y-1), array($y));
}
function y($x,$z){
foreach (range($x, count(x($z))) as $i) {
yield $i;
}
}
function z($x,$y){
return array_map(function($w){
return '<td>'.(1+$w).'</td>';
}, (iterator_to_array(y($x,$y))));
}
for($i=0;$i<4;$i++){
echo $i>0?"</tr><tr>":"";
foreach(z(4*$i, 4*($i+1)-1) as $z) echo $z;
}
echo "</tr>";
echo "</table>";
?>
我需要在 PHP 中进行一些 "for" 循环,这将生成带有垂直编号单元格的 table。为了更好地理解,这是图像:
我相信你正在努力实现这样的目标
<?php
$x = 0;
echo "<table >";
echo "<tr>";
for($x=1; $x<13; $x++){
echo "<td>$x</td>";
if($x%4 == 0 ){
echo "<tr>"."\n";
}
}
echo "</tr></table>";
?>
祝你好运!
这是您要查找的代码:
<?php
$col = 4; //number of desired columns
$row = 5; //number of desired rows
echo "<table>\n";
for($i = 1; $i<$row+1; $i++)
{
echo "<tr>\n";
for($c = 0; $c<$col; $c++)
{
echo "<td>".($i + ($c*$row))."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n"
?>
这样就可以了:
<?php
echo "<table>";
echo "<tr>";
function x($y){
return ($y<=1)?array($y):array_merge(x($y-1), array($y));
}
function y($x,$z){
foreach (range($x, count(x($z))) as $i) {
yield $i;
}
}
function z($x,$y){
return array_map(function($w){
return '<td>'.(1+$w).'</td>';
}, (iterator_to_array(y($x,$y))));
}
for($i=0;$i<4;$i++){
echo $i>0?"</tr><tr>":"";
foreach(z(4*$i, 4*($i+1)-1) as $z) echo $z;
}
echo "</tr>";
echo "</table>";
?>