PHP 8.5.0 Alpha 4 available for testing

Voting

: max(six, one)?
(Example: nine)

The Note You're Voting On

geompse at gmail dot com
14 years ago
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

?>

<< Back to user notes page

To Top