When a foreach control structure uses the same variable for both the $key as well as the $value assignment, the key will be disregarded and be inaccessible and the variable will contain the value.
Mix in reference assignments and the behaviour becomes even more unpredictable.
This is a coding error. Either use unique variables for the key and the value or don't assign the key.
]]>
</standard>
<code_comparison>
<codetitle="Valid: using unique variables.">
<![CDATA[
foreach ($array as $k => $v ) {}
]]>
</code>
<codetitle="Invalid: using the same variable for both the key as well as the value.">