2013-02-09 385 views
0

我創建了一個數組來列出他們所學課程的學生成績。但是,我收到第33行的PHP錯誤:未定義的偏移量。該表似乎以我想要的方式顯示,我似乎在上載​​到EasyPHP後在瀏覽器中反覆出現此錯誤。我做錯了什麼?PHP錯誤:未定義偏移量

<?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>"; 


?> 

回答

0

您正在詢問四列,但只有三列出現在該陣列中。

更換

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

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

但是,錯誤消息應該告訴你的行發生錯誤的指標,而且應該可以告訴你。