title: PHP "Undefined Index" multidimensional array with nested index
body: <p>I actually had this code working just fine, but I did some things to make it look a lot more clean and concise by using array keys. You can see how my first go at it is kind of sloppy looking with the keys being <code>$classes[$i+3]</code> etc. It works fine, but I wanted to make it more readable and make more sense at a glance.</p>
  
  <p>This is the error message:</p>
  
  <blockquote>
    <p>Notice: Undefined index: A in C:\xampp\htdocs\CreateaTranscript.php on line 127
        ("A" is a key in the "$grade_conversion" array that relates to a decimal value for computing the user's GPA.)</p>
  </blockquote>
  
  <p>This is the line of code I use to have that actually worked:</p>
  
  <pre><code>$grade_points += $grade_conversion[$classes[$i+3]] * $classes[$i+2];
  </code></pre>
  
  <p>This is the line of code causing the error:</p>
  
  <pre><code>$grade_points += $grade_conversion[$course[$i]['grade']] * $course[$i]['credit_hours'];
  </code></pre>
  
  <p>I tried enclosing the multi-dimensional array in 's. However, it just creates a different error that prevents the script from running. I know the basic issue is that the compiler sees an array key not enclosed in 's. However, why does it work with the normal array and not the multi-dimensional array?</p>
  
  <pre><code>$grade_conversion=array(
      'A' =&gt; 4,
      'A-' =&gt; 3.7,
      'B+' =&gt; 3.3,
      'B' =&gt; 3.0,
      'B-' =&gt; 2.7,
      'C+' =&gt; 2.3,
      'C' =&gt; 2.0,
      'C-' =&gt; 1.7,
      'D+' =&gt; 1.3,
      'D' =&gt; 1,
      'D+' =&gt; 0.7,
      'F' =&gt; 0,
  );
  </code></pre>
  
  <p>I was trying to keep this concise. Is it possible to use an index in the manner I declared it? It worked fine before I switched it over to a multi-dimensional array. I'm going to add a sample of the for statement that the line was from:</p>
  
  <pre><code>for($i = 0;$i &lt; count($course);$i++){
  print "&lt;tr bgcolor = 'F8F8F8'&gt;&lt;td&gt;" . $course[$i]['course_id'] . "&lt;td&gt;" . $course[$i]['course_name'] . "&lt;/td&gt;&lt;td&gt;" . $course[$i]['credit_hours'] . "&lt;/td&gt;&lt;td&gt;" . $course[$i]['grade'] . "&lt;/td&gt;&lt;/tr&gt;";
  
  //Keep a running count of credit hours for the GPA equation.
  //Keep a running total of grade points using the $grade_conversion array
  $total_credit_hours += $course[$i]['credit_hours'];
  $grade_points += $grade_conversion[$course[$i]['grade']] * $course[$i]['credit_hours'];
  
  }
  </code></pre>
  
  <p>The $course array is create by reading data from a file.</p>
  
  <p>Here is how the $course array is created. The data is pulled from a data file line by line.</p>
  
  <pre><code>            $fh=fopen($file, "r");
          $j = 0;
          while (!feof($fh)){
                  $course[$j]['course_id'] = fgets($fh);
                  $course[$j]['course_name'] = fgets($fh);
                  $course[$j]['credit_hours'] = fgets($fh);
                  $course[$j]['grade'] = fgets($fh);
                  $j++;
          }
          fclose($fh);
  </code></pre>