[英]How to auto numbering/increment number of every column in table using PHP?
I'm using foreach
and implode
function with below code: 我正在使用以下代码的foreach
和implode
函数:
$i = 0;
foreach ($dates as $date=>$hour)
{
?>
<th><?php echo $i." ".implode("</th>\n\t\t<th>\n", $hour); ?></th>
<?php
$i++;
}
The goal is to show incrementing column number but as i tested above code it was only show number 1. 目标是显示递增的列号,但是正如我在上面的代码中测试的那样,它仅显示第1个。
My question is: How to auto numbering/increment number of every column in table using PHP? 我的问题是:如何使用PHP自动编号/增加表中每列的编号?
Don't use implode. 不要使用内爆。
Your $i gets incremented only once per set $hours, but you implode all hours in one go. 您的$ i每设定的$ hours仅增加一次,但是您一次只能爆满所有小时数。
I don't know what is exactly inside your $dates array, and you didn't say what your desired output should be. 我不知道您的$ dates数组中到底有什么,您也没有说期望的输出是什么。
The way you approach it now will create a WHOLE bunch of table headers. 您现在使用的方式将创建一堆表头。
You know best what you want, but my guess is think you should not use implode, and your counter $i will work as intended. 您最清楚自己想要的是什么,但是我的猜测是您不应该使用implode,并且计数器$ i将按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.