title: PHP: get current array key?
body: <pre><code>$array = ( 
      array('1231415'=&gt;array('foo'=&gt;'bar', 'test'=&gt; 1)),
      array('32434'=&gt;array('foo'=&gt;'bar', 'test'=&gt; '0')),
      array('123244'=&gt;array('foo'=&gt;'bar', 'test'=&gt; 0)),
      array('193928'=&gt;array('foo'=&gt;'bar', 'test'=&gt; 1))
  );
  </code></pre>
  
  <p>I have an array that has (many) random keys, the ID number. I need to test each array within if 'test' = 1, and so I made a <code>foreach</code> loop.</p>
  
  <pre><code>foreach ($array as $sub) {
    if ($sub['test'] == '1' ) {
       echo 'User: ' . $sub . ' has test = 1';
    }
  }
  </code></pre>
  
  <p>This works, but it returns 'User: Array has test = 1'</p>
  
  <p>How on earth to I get which ID number, (that random number) has test=1 in it?</p>
  
  <p>I tried doing <code>$array as $sub=&gt;$value</code>, but for some reason it just makes the <code>foreach</code> not work. Thank you!</p>