PHP: get current array key?

azerion

New Member
\[code\]$array = ( array('1231415'=>array('foo'=>'bar', 'test'=> 1)), array('32434'=>array('foo'=>'bar', 'test'=> '0')), array('123244'=>array('foo'=>'bar', 'test'=> 0)), array('193928'=>array('foo'=>'bar', 'test'=> 1)));\[/code\]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.\[code\]foreach ($array as $sub) { if ($sub['test'] == '1' ) { echo 'User: ' . $sub . ' has test = 1'; }}\[/code\]This works, but it returns 'User: Array has test = 1'How on earth to I get which ID number, (that random number) has test=1 in it?I tried doing \[code\]$array as $sub=>$value\[/code\], but for some reason it just makes the \[code\]foreach\[/code\] not work. Thank you!
 
Back
Top