ChrisB: komischer Wert für key() in einer foreach-Schleife

Beitrag lesen

Hi,

<?php

$arr = array ('a', 'b', 'c', 'd', 'e');
$file = 'b';

foreach ( $arr as $x )
{
if ($x == $file)
$key = key($arr);
}

echo $key
?>


>   
> echo $key gibt mir nun den Wert 2 aus, obwohl doch das Element 'b' eindeutig den Index 1 hat, was ich auch mit print\_r($arr) überprüft habe. auch für andere Werte von $file ist $key immer um 1 zu gross, ausser für $file = 'e', da ist $key = 0.  
  
<http://www.php.net/manual/en/control-structures.foreach.php>:  
“On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one”  
  
MfG ChrisB  
  

-- 
RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?