Remove windows encoding from `.php` files
[hiphop-php.git] / hphp / test / zend / bad / tests / lang / foreachLoop.014.php
blob6e09b32df5e23f4690570db80b4b5cc0c9b65ab0
1 <?php
3 define('MAX_LOOPS',5);
5 function withRefValue($elements, $transform) {
6 echo "\n---( Array with $elements element(s): )---\n";
7 //Build array:
8 for ($i=0; $i<$elements; $i++) {
9 $a[] = "v.$i";
11 $counter=0;
13 $ref = &$a;
15 echo "--> State of referenced array before loop:\n";
16 var_dump($a);
18 echo "--> Do loop:\n";
19 foreach ($a as $k=>$v) {
20 echo " iteration $counter: \$k=$k; \$v=$v\n";
21 eval($transform);
22 $counter++;
23 if ($counter>MAX_LOOPS) {
24 echo " ** Stuck in a loop! **\n";
25 break;
29 echo "--> State of array after loop:\n";
30 var_dump($a);
34 echo "\nPopping elements off end of a referenced array";
35 $transform = 'array_pop($a);';
36 withRefValue(1, $transform);
37 withRefValue(2, $transform);
38 withRefValue(3, $transform);
39 withRefValue(4, $transform);
41 echo "\n\n\nShift elements off start of a referenced array";
42 $transform = 'array_shift($a);';
43 withRefValue(1, $transform);
44 withRefValue(2, $transform);
45 withRefValue(3, $transform);
46 withRefValue(4, $transform);
48 echo "\n\n\nRemove current element of a referenced array";
49 $transform = 'unset($a[$k]);';
50 withRefValue(1, $transform);
51 withRefValue(2, $transform);
52 withRefValue(3, $transform);
53 withRefValue(4, $transform);
55 echo "\n\n\nAdding elements to the end of a referenced array";
56 $transform = 'array_push($a, "new.$counter");';
57 withRefValue(1, $transform);
58 withRefValue(2, $transform);
59 withRefValue(3, $transform);
60 withRefValue(4, $transform);
62 echo "\n\n\nAdding elements to the start of a referenced array";
63 $transform = 'array_unshift($a, "new.$counter");';
64 withRefValue(1, $transform);
65 withRefValue(2, $transform);
66 withRefValue(3, $transform);
67 withRefValue(4, $transform);