1--TEST--
2Test each() function : usage variations - Referenced variables
3--INI--
4allow_call_time_pass_reference=on
5--FILE--
6<?php
7/* Prototype  : array each(array $arr)
8 * Description: Return the currently pointed key..value pair in the passed array,
9 * and advance the pointer to the next element
10 * Source code: Zend/zend_builtin_functions.c
11 */
12
13/*
14 * Test behaviour of each() when:
15 * 1. Passed an array made up of referenced variables
16 * 2. Passed an array as $arr argument by reference
17 */
18
19echo "*** Testing each() : usage variations ***\n";
20
21echo "\n-- Array made up of referenced variables: --\n";
22$val1 = 'foo';
23$val2 = 'bar';
24
25$arr1 = array('one' => &$val1, &$val2);
26
27echo "-- Call each until at the end of the array: --\n";
28var_dump( each($arr1) );
29var_dump( each($arr1) );
30var_dump( each($arr1) );
31
32
33echo "\n-- Pass an array by reference to each(): --\n";
34$arr2 = array('zero', 'one', 'two');
35
36var_dump( each(&$arr2) );
37echo "-- Check original array: --\n";
38var_dump($arr2);
39
40echo "Done";
41?>
42
43--EXPECTF--
44*** Testing each() : usage variations ***
45
46-- Array made up of referenced variables: --
47-- Call each until at the end of the array: --
48array(4) {
49  [1]=>
50  string(3) "foo"
51  ["value"]=>
52  string(3) "foo"
53  [0]=>
54  string(3) "one"
55  ["key"]=>
56  string(3) "one"
57}
58array(4) {
59  [1]=>
60  string(3) "bar"
61  ["value"]=>
62  string(3) "bar"
63  [0]=>
64  int(0)
65  ["key"]=>
66  int(0)
67}
68bool(false)
69
70-- Pass an array by reference to each(): --
71array(4) {
72  [1]=>
73  string(4) "zero"
74  ["value"]=>
75  string(4) "zero"
76  [0]=>
77  int(0)
78  ["key"]=>
79  int(0)
80}
81-- Check original array: --
82array(3) {
83  [0]=>
84  string(4) "zero"
85  [1]=>
86  string(3) "one"
87  [2]=>
88  string(3) "two"
89}
90Done
91