<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$table = array ("1", "2", "3", "4", "5");
$count = count($table);
echo "<table border='1'>";
$rows = 5;
for($i=0; $i <= $count; $i = $i + $rows)
{
echo "<tr>";
for($z = 0; $z < $rows; $z++)
{
if ($table[$i + $z] !=0)
echo "<td>This is row {$table[$i + $z]}</td></tr>";
else
echo "<td> </td></tr>";
}
}
echo "</table>"
?>
</body>
</html>
这是我一段时间以来一直试图让它工作的代码,虽然其他一切都很好,但当我运行它时就会出现问题。它显示了我想要的表格,但它在表格下发布:
Notice: Undefined offset: 5 in [file location] on line 22
Notice: Undefined offset: 6 in [file location] on line 22
Notice: Undefined offset: 7 in [file location] on line 22
Notice: Undefined offset: 8 in [file location] on line 22
Notice: Undefined offset: 9 in [file location] on line 22
我知道问题出在“!= 0”值附近,但是无论我将其更改为什么,它要么刷新整个工作,要么重复相同的消息。