title: Array Undefined index error (notice) in PHP
body: <p>I have this function:</p>
  
  <pre><code>function coin_matrix($test, $revs) {
      $coin = array();
  
      for ($i = 0; $i &lt; count($test); $i++) {
          foreach ($revs as $j =&gt; $rev) {
              foreach ($revs as $k =&gt; $rev) {
              if ($j != $k &amp;&amp; 
                  $test[$i][$j] != null &amp;&amp; 
                  $test[$i][$k] != null) {
  
                  $coin[$test[$i][$j]][$test[$i][$k]] += 1 / ($some_var - 1);
                  }
              }
          }
      }
      return $coin;
  }
  </code></pre>
  
  <p>where</p>
  
  <pre><code>$test = array(
  array('3'=&gt;'1','5'=&gt;'1'),
  array('3'=&gt;'2','5'=&gt;'2'),
  array('3'=&gt;'1','5'=&gt;'2'),
  array('3'=&gt;'1','5'=&gt;'1'));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$revs = array('3'=&gt;'A','5'=&gt;'B');
  </code></pre>
  
  <p>the problem is that when I run it, it returns these errors (notices):</p>
  
  <p>Notice:  Undefined index:  1 at line 10</p>
  
  <p>Notice:  Undefined index:  1 at line 10</p>
  
  <p>Notice:  Undefined index:  2 at line 10</p>
  
  <p>Notice:  Undefined index:  2 at line 10</p>
  
  <p>Notice:  Undefined index:  2 at line 10</p>
  
  <p>Notice:  Undefined index:  1 at line 10</p>
  
  <p>which is this line: <code>$coin[$test[$i][$j]][$test[$i][$k]] += 1 / ($some_var - 1);</code></p>
  
  <p>The problem is that at the end the function returns the correct matrix (array) and if I test to see if <code>$coin[$test[$i][$j]][$test[$i][$k]]</code> exists, then it doesn't return it anymore.</p>
  
  <p>Any suggestion is greatly appreciated!</p>
  
  <p>Thanks!</p>