Make WordPress Core

Ticket #21169: next-to-each-php.php

File next-to-each-php.php, 1.0 KB (added by devesine, 14 years ago)
Line 
1<?php
2$GLOBALS['taskary'] = array(
3 "1" => 1,
4 "2" => 2,
5 "3" => 3,
6 "4" => 4,
7
8);
9
10echo "should print 1234" . PHP_EOL;
11reset($GLOBALS['taskary']);
12while ($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}
20echo 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
31echo "should print 1245 - correctly, since 3 was removed" . PHP_EOL;
32reset($GLOBALS['taskary']);
33while ($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}
41echo PHP_EOL;
42
43$GLOBALS['taskary'] = array(
44 "1" => 1,
45 "2" => 2,
46 "3" => 3,
47 "4" => 4,
48
49);
50
51echo "should print 1234 - incorrectly prints 124 (skipping 3)" . PHP_EOL;
52reset($GLOBALS['taskary']);
53do {
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);
61echo PHP_EOL;