PHP错误:未定义的偏移量

时间:2013-02-09 22:01:04

标签: php

我创建了一个数组,列出了他们所学课程的学生成绩。但是,我收到第33行的PHP错误:未定义的偏移。该表似乎以我想要的方式显示,我似乎在上传到EasyPHP后在我的浏览器中反复出现此错误。我做错了什么?

<?php
$studentGrades = array(
       array(
          array("<b>Frank Thomas</b>","<b>Courses Taken</b>", "<b>Course Grade</b>"),
          array("Frank Thomas", "Compilers",  "<i>D</i>"),
          array("Frank Thomas", "Logic and Automated Reasoning", "<i>A</i>"),
          array("Frank Thomas", "Advanced Robotics", "<i>A</i>")                      
       ),
       array(
             array("<b>Garry Beebs</b>", "Intro to Computer Vision", "<i>B</i>"),
             array("Garry Beebs", "Machine Learning", "<i>B</i>"),
             array("Garry Beebs", "Compilers", "<i>A</i>"), 
             array("Garry Beebs", "Interactive Computer Graphics", "<i>A</i>") 
            ),
       array(
             array("<b>Jesse Kline</b>", "Distributed Systems", "<i>A</i>"),
             array("Jesse Kline", "Intro to Artificial Intelligence", "<i>C</i>"),
             array("Jesse Kline", "Advanced Robotics", "<i>B</i>"), 
             array("Jesse Kline", "Natural Language Processing", "<i>B</i>")
            )
       );

echo '<table border="2">';
for ( $arrnum = 0; $arrnum < 3; $arrnum++ )
{

for ( $row = 0; $row < 4; $row++ ) 
{
echo '<tr>';

for ( $col = 0; $col < 4; $col++ )
{
 if ($studentGrades[$arrnum][$row][$col] == '') 
 {
    echo "<td> </td>";
 }
 else
 {
    if ($row == 0 and $col == 0)
    {
    echo "<td>". $studentGrades[$arrnum][$row][$col] . "</td>";
    }
    else if ($row != 0 and $col == 0)
    {
        echo "<td> </td>";
    }
    else
    {
    echo "<td>". $studentGrades[$arrnum][$row][$col] . "</td>";
    }                   
 } 
} 

}
echo "</tr>";
}   
echo "</table>";


?>

1 个答案:

答案 0 :(得分:0)

您要求的是四列,但该数组中只有三列。

替换

for ( $col = 0; $col < 4; $col++ )

for ( $col = 0; $col < 3; $col++ )

但是,错误消息应该告诉你错误发生的行和索引,这应该会让你失望。