如何检查while循环中的最后一个条目,并在php中的表的最后一行之后插入行


how to check the last entry in a while loop and insert row after the last row in a table in php

是否可以在不知道第一行数的情况下,检查'while'循环中的每一行是否是最后一行?

您可以使用end函数将指针移动到最后一个数组索引,如下所示:

$your_array = mysqli_fetch_assoc($result);
end($your_array);         
$last_key = key($your_array);

这样你就有了数组的最后一个键,如果你想知道while循环中的最后一行,你可以将while循环的键与最后一个密钥进行比较,如下所示:

while (list ($key, $val) = each ($your_array) )
{
    if($key==$last_key) {
    //write your code here
    }
}