1--TEST--
2Test each() function : usage variations - keys of different data types
3--FILE--
4<?php
5/* Prototype  : array each(array $arr)
6 * Description: Return the currently pointed key..value pair in the passed array,
7 * and advance the pointer to the next element
8 * Source code: Zend/zend_builtin_functions.c
9 */
10
11/*
12 * Pass each() arrays where the keys are different data types to test behaviour
13 */
14
15echo "*** Testing each() : usage variations ***\n";
16
17//get an unset variable
18$unset_var = 10;
19unset ($unset_var);
20
21// heredoc string
22$heredoc = <<<EOT
23hello world
24EOT;
25
26// unexpected values to be passed as $arr
27$inputs = array(
28
29       // int data
30/*1*/  'int' => array(
31       0 => 'zero',
32       1 => 'one',
33       12345 => 'positive',
34       -2345 => 'negative',
35       ),
36
37       // float data
38/*2*/  'float' => array(
39       10.5 => 'positive',
40       -10.5 => 'negative',
41       .5 => 'half',
42       ),
43
44/*3*/  'extreme floats' => array(
45       12.3456789000e6 => 'large',
46       12.3456789000E-10 => 'small',
47       ),
48
49       // null data
50/*4*/ 'null uppercase' => array(
51       NULL => 'null 1',
52       ),
53
54/*5*/  'null lowercase' => array(
55       null => 'null 2',
56       ),
57
58       // boolean data
59/*6*/ 'bool lowercase' => array(
60       true => 'lowert',
61       false => 'lowerf',
62       ),
63
64/*7*/  'bool uppercase' => array(
65       TRUE => 'uppert',
66       FALSE => 'upperf',
67       ),
68
69       // empty data
70/*8*/ 'empty double quotes' => array(
71       "" => 'emptyd',
72       ),
73
74/*9*/  'empty single quotes' => array(
75       '' => 'emptys',
76       ),
77
78       // string data
79/*10*/ 'string' => array(
80       "stringd" => 'stringd',
81       'strings' => 'strings',
82       $heredoc => 'stringh',
83       ),
84
85       // undefined data
86/*11*/ 'undefined' => array(
87       @$undefined_var => 'undefined',
88       ),
89
90       // unset data
91/*12*/ 'unset' => array(
92       @$unset_var => 'unset',
93       ),
94);
95
96// loop through each element of $inputs to check the behavior of each()
97$iterator = 1;
98foreach($inputs as $key => $input) {
99  echo "\n-- Iteration $iterator: $key data --\n";
100  var_dump( each($input) );
101  $iterator++;
102};
103
104echo "Done";
105?>
106--EXPECTF--
107*** Testing each() : usage variations ***
108
109-- Iteration 1: int data --
110
111Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
112array(4) {
113  [1]=>
114  string(4) "zero"
115  ["value"]=>
116  string(4) "zero"
117  [0]=>
118  int(0)
119  ["key"]=>
120  int(0)
121}
122
123-- Iteration 2: float data --
124array(4) {
125  [1]=>
126  string(8) "positive"
127  ["value"]=>
128  string(8) "positive"
129  [0]=>
130  int(10)
131  ["key"]=>
132  int(10)
133}
134
135-- Iteration 3: extreme floats data --
136array(4) {
137  [1]=>
138  string(5) "large"
139  ["value"]=>
140  string(5) "large"
141  [0]=>
142  int(12345678)
143  ["key"]=>
144  int(12345678)
145}
146
147-- Iteration 4: null uppercase data --
148array(4) {
149  [1]=>
150  string(6) "null 1"
151  ["value"]=>
152  string(6) "null 1"
153  [0]=>
154  string(0) ""
155  ["key"]=>
156  string(0) ""
157}
158
159-- Iteration 5: null lowercase data --
160array(4) {
161  [1]=>
162  string(6) "null 2"
163  ["value"]=>
164  string(6) "null 2"
165  [0]=>
166  string(0) ""
167  ["key"]=>
168  string(0) ""
169}
170
171-- Iteration 6: bool lowercase data --
172array(4) {
173  [1]=>
174  string(6) "lowert"
175  ["value"]=>
176  string(6) "lowert"
177  [0]=>
178  int(1)
179  ["key"]=>
180  int(1)
181}
182
183-- Iteration 7: bool uppercase data --
184array(4) {
185  [1]=>
186  string(6) "uppert"
187  ["value"]=>
188  string(6) "uppert"
189  [0]=>
190  int(1)
191  ["key"]=>
192  int(1)
193}
194
195-- Iteration 8: empty double quotes data --
196array(4) {
197  [1]=>
198  string(6) "emptyd"
199  ["value"]=>
200  string(6) "emptyd"
201  [0]=>
202  string(0) ""
203  ["key"]=>
204  string(0) ""
205}
206
207-- Iteration 9: empty single quotes data --
208array(4) {
209  [1]=>
210  string(6) "emptys"
211  ["value"]=>
212  string(6) "emptys"
213  [0]=>
214  string(0) ""
215  ["key"]=>
216  string(0) ""
217}
218
219-- Iteration 10: string data --
220array(4) {
221  [1]=>
222  string(7) "stringd"
223  ["value"]=>
224  string(7) "stringd"
225  [0]=>
226  string(7) "stringd"
227  ["key"]=>
228  string(7) "stringd"
229}
230
231-- Iteration 11: undefined data --
232array(4) {
233  [1]=>
234  string(9) "undefined"
235  ["value"]=>
236  string(9) "undefined"
237  [0]=>
238  string(0) ""
239  ["key"]=>
240  string(0) ""
241}
242
243-- Iteration 12: unset data --
244array(4) {
245  [1]=>
246  string(5) "unset"
247  ["value"]=>
248  string(5) "unset"
249  [0]=>
250  string(0) ""
251  ["key"]=>
252  string(0) ""
253}
254Done
255