I tend to find that when using foreach stuctures without using references, some elements of the array are missing.
$array = array();
/* ... */
$array[] = 1;
$array[] = 2;
$array[] = 3;
/* ... */
print_r($array); /* print_r always shows all elements */
foreach ($array as $element) { /* missing elements */ }
foreach ($array as &$element) { /* does a fine job */ }
I have had three independent occurrences of this in my code. The fix is easy (add &), but it sounds like a bug either in PHP or in my setup...
Are more people experiencing this? What is the problem?
PHP 5.4.12
EDIT
Case:
$a = array();
$a[] = 1;
$a[] = 2;
$a[] = 3;
foreach ($a as &$e)
{
echo $e;
}
echo '<br>';
foreach ($a as $e)
{
echo $e;
}
Output:
123
122