$animals = array('cat', 'dog', 'horse', 'elephant');
foreach($animals as $animal)
{
var_dump($animal);
next($animals);
}
The above code: cat, dog, horse, elephant. I thought that the function nextshould move the internal pointer $animalsand so I should get this output instead of: cat, horse.
How to make $ animals internal pointer move forward (and back) so that it is affected in foreach?
EDIT 1:
From the manual:
Since foreach relies on a pointer to an internal array, changing it within a loop can lead to unexpected behavior.
However, I think this is what I need to do.
EDIT 2:
In the section "Your common sense" I will provide a more detailed explanation of my problem. Here is some psuedo code:
array $foos;
start loop of $foos
- do thing
- do thing
- do thing
- keep doing thing
loop
, , № 3. , , for ($i = 0 ... .