我正在尝试选择带有 col1 - col3 的表。我需要使用 array_shift 消除 col2 row1。这是我的代码:
$data = array();
while ($row = mysqli_fetch_array($result){
$data[] = $row['time'];
array_shift($data);
** mytable**
echo'<tr>'.$data.'<td>';
}
看起来我错过了一些东西,它在表格中没有打印任何内容。请指教。看起来如果我在 while 循环
之后使用 array_shift
,它可以工作,但它会打印如下内容:
Array ( [0] => 00:00:05 [1] => 00:00:14 [2] => 00:00:09 [3] => 00:02:24 [4] => 00:01:13 [5] => 00:00:11 [6] => 00:00:09 )
它消除了我想要的 col2 的第一行,但我不知道如何将其放入表中。请让我知道我想念什么...
最佳答案
如果您只想删除第一个结果并将数组打印为列,可以使用以下方法(不是最好的方法,但这是您已有的方法的逻辑步骤):
$data = array();
while ($row = mysqli_fetch_array($result){
$data[] = $row['time'];
}
array_shift($data);
echo "<tr>";
foreach ($data as $element) {
echo'<td>'.$element.'</td>';
}
echo "</tr>"
我假设您在某个时刻在上面的某个位置打开了一张 table 。
关于php - array_shift 如何在 while 循环内工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46464025/