| 1 | <?php |
|---|
| 2 | $GLOBALS['taskary'] = array( |
|---|
| 3 | "1" => 1, |
|---|
| 4 | "2" => 2, |
|---|
| 5 | "3" => 3, |
|---|
| 6 | "4" => 4, |
|---|
| 7 | |
|---|
| 8 | ); |
|---|
| 9 | |
|---|
| 10 | echo "should print 1234" . PHP_EOL; |
|---|
| 11 | reset($GLOBALS['taskary']); |
|---|
| 12 | while ($next = each($GLOBALS['taskary'])) { |
|---|
| 13 | $val = $next['value']; |
|---|
| 14 | echo $val; |
|---|
| 15 | if ($val == 2) { |
|---|
| 16 | // Remove the current array element |
|---|
| 17 | unset($GLOBALS['taskary'][2]); |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | echo PHP_EOL; |
|---|
| 21 | |
|---|
| 22 | $GLOBALS['taskary'] = array( |
|---|
| 23 | "1" => 1, |
|---|
| 24 | "2" => 2, |
|---|
| 25 | "3" => 3, |
|---|
| 26 | "4" => 4, |
|---|
| 27 | "5" => 5, |
|---|
| 28 | |
|---|
| 29 | ); |
|---|
| 30 | |
|---|
| 31 | echo "should print 1245 - correctly, since 3 was removed" . PHP_EOL; |
|---|
| 32 | reset($GLOBALS['taskary']); |
|---|
| 33 | while ($next = each($GLOBALS['taskary'])) { |
|---|
| 34 | $val = $next['value']; |
|---|
| 35 | echo $val; |
|---|
| 36 | if ($val == 2) { |
|---|
| 37 | // Remove the next array element |
|---|
| 38 | unset($GLOBALS['taskary'][3]); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | echo PHP_EOL; |
|---|
| 42 | |
|---|
| 43 | $GLOBALS['taskary'] = array( |
|---|
| 44 | "1" => 1, |
|---|
| 45 | "2" => 2, |
|---|
| 46 | "3" => 3, |
|---|
| 47 | "4" => 4, |
|---|
| 48 | |
|---|
| 49 | ); |
|---|
| 50 | |
|---|
| 51 | echo "should print 1234 - incorrectly prints 124 (skipping 3)" . PHP_EOL; |
|---|
| 52 | reset($GLOBALS['taskary']); |
|---|
| 53 | do { |
|---|
| 54 | $val = current($GLOBALS['taskary']); |
|---|
| 55 | echo $val; |
|---|
| 56 | if ($val == 2) { |
|---|
| 57 | unset($GLOBALS['taskary'][2]); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | } while (next($GLOBALS['taskary']) !== false); |
|---|
| 61 | echo PHP_EOL; |
|---|