Be carefull with Iterator when using nested loops or deleting items inside the collection while looping over it.
It can be tricky to detect.
This unexpected behavior is pertinent if you think about it long enough.
<?php
foreach($it as $key => $value)
echo $value;
#output: value1, value2, value3
foreach($it as $key => $value)
foreach($it as $key => $value)
echo $value;
#output: value1, value2, value3
foreach($it as $key => $value)
foreach(clone $it as $key => $value)
echo $value;
#output: value1, value2, value3, value1, value2, value3, value1, value2, value3
foreach($it as $key => $value)
{
echo $value;
array_shift($it->values);
}
#ouput: value1, value3
?>