-6
<!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>&nbsp;</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”值附近,但是无论我将其更改为什么,它要么刷新整个工作,要么重复相同的消息。

4

4 回答 4

2
  1. 您错过;了以下陈述。

    echo "</table>"
    
  2. 您正在以 5 步进行迭代。$i + $rows$table最多可以进行$table[4].
  3. 错误/通知是因为相同的。
于 2013-02-09T12:52:31.080 回答
1

我得到了相同的错误代码,但我设法找到了问题。您收到的错误消息与数组有关。看来您是在引用未定义的数组 [key]: for($i=0; $i <= $count; $i = $i + $rows)$i = $i + $rows是罪魁祸首。示例:$i = 0所以array[5] 并且$rows=5;0 + 5 = 5 在数组中不存在。它仅与$table数组一起达到 4。希望这可以帮助您和/或其他人。

于 2015-02-15T08:49:30.873 回答
-1
<?php
if(isset($_POST['submit'])){
    $the_file = file($_FILES['the_file']['tmp_name']);
    for( $i = 0; $i < count($myfile); ++$i){
        echo $myfile[$i] . "<br/>";
        echo "Line " . ( $i + 1 ) . " is  " .strlen($myfile[$i]) . " characters long<br/>";
    }
}
?>


<form method="post" action="myphp.php" enctype='multipart/form-data' >
    <input type="file" name="the_file" value="Yes"/>
    <input type="submit" name="submit" value="No"/>
</form>
于 2013-12-10T15:58:58.890 回答
-1

我认为发布此问题的人已经解决了。只需在这条线上稍作改动for($i=0; $i <= $count; $i = $i + $rows)即可解决问题。

for($i=0; $i <= $count; $i = $i + $rows) // for($i=0; $i < $count; $i = $i + $rows)用这个。

于 2020-09-15T21:00:37.757 回答