1--TEST--
2Test each() function : usage variations - arrays 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 arrays of different data types as $arr argument to each() 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// get a class
22class classA
23{
24  public function __toString() {
25    return "Class A object";
26  }
27}
28
29// heredoc string
30$heredoc = <<<EOT
31hello world
32EOT;
33
34// get a resource variable
35$fp = fopen(__FILE__, "r");
36
37// arrays of different data types to be passed as $arr
38$inputs = array(
39
40       // int data
41/*1*/  'int' => array(
42	   0,
43       1,
44       12345,
45       -2345,
46       ),
47
48       // float data
49/*2*/  'float' => array(
50       10.5,
51       -10.5,
52       12.3456789000e10,
53       12.3456789000E-10,
54       .5,
55       ),
56
57       // null data
58/*3*/ 'null' => array(
59       NULL,
60       null,
61       ),
62
63       // boolean data
64/*4*/ 'bool' => array(
65       true,
66       false,
67       TRUE,
68       FALSE,
69       ),
70
71       // empty data
72/*5*/ 'empty string' => array(
73       "",
74       '',
75       ),
76
77/*6*/ 'empty array' => array(
78       ),
79
80       // string data
81/*7*/ 'string' => array(
82       "string",
83       'string',
84       $heredoc,
85       ),
86
87       // object data
88/*8*/ 'object' => array(
89       new classA(),
90       ),
91
92       // undefined data
93/*9*/ 'undefined' => array(
94       @$undefined_var,
95       ),
96
97       // unset data
98/*10*/ 'unset' => array(
99       @$unset_var,
100       ),
101
102       // resource variable
103/*11*/ 'resource' => array(
104       $fp
105       ),
106);
107
108// loop through each element of $inputs to check the behavior of each()
109$iterator = 1;
110foreach($inputs as $key => $input) {
111  echo "\n-- Iteration $iterator: $key data --\n";
112  var_dump( each($input) );
113  $iterator++;
114};
115
116fclose($fp);
117
118echo "Done";
119?>
120
121--EXPECTF--
122*** Testing each() : usage variations ***
123
124-- Iteration 1: int data --
125array(4) {
126  [1]=>
127  int(0)
128  ["value"]=>
129  int(0)
130  [0]=>
131  int(0)
132  ["key"]=>
133  int(0)
134}
135
136-- Iteration 2: float data --
137array(4) {
138  [1]=>
139  float(10.5)
140  ["value"]=>
141  float(10.5)
142  [0]=>
143  int(0)
144  ["key"]=>
145  int(0)
146}
147
148-- Iteration 3: null data --
149array(4) {
150  [1]=>
151  NULL
152  ["value"]=>
153  NULL
154  [0]=>
155  int(0)
156  ["key"]=>
157  int(0)
158}
159
160-- Iteration 4: bool data --
161array(4) {
162  [1]=>
163  bool(true)
164  ["value"]=>
165  bool(true)
166  [0]=>
167  int(0)
168  ["key"]=>
169  int(0)
170}
171
172-- Iteration 5: empty string data --
173array(4) {
174  [1]=>
175  string(0) ""
176  ["value"]=>
177  string(0) ""
178  [0]=>
179  int(0)
180  ["key"]=>
181  int(0)
182}
183
184-- Iteration 6: empty array data --
185bool(false)
186
187-- Iteration 7: string data --
188array(4) {
189  [1]=>
190  string(6) "string"
191  ["value"]=>
192  string(6) "string"
193  [0]=>
194  int(0)
195  ["key"]=>
196  int(0)
197}
198
199-- Iteration 8: object data --
200array(4) {
201  [1]=>
202  object(classA)#%d (0) {
203  }
204  ["value"]=>
205  object(classA)#%d (0) {
206  }
207  [0]=>
208  int(0)
209  ["key"]=>
210  int(0)
211}
212
213-- Iteration 9: undefined data --
214array(4) {
215  [1]=>
216  NULL
217  ["value"]=>
218  NULL
219  [0]=>
220  int(0)
221  ["key"]=>
222  int(0)
223}
224
225-- Iteration 10: unset data --
226array(4) {
227  [1]=>
228  NULL
229  ["value"]=>
230  NULL
231  [0]=>
232  int(0)
233  ["key"]=>
234  int(0)
235}
236
237-- Iteration 11: resource data --
238array(4) {
239  [1]=>
240  resource(%d) of type (stream)
241  ["value"]=>
242  resource(%d) of type (stream)
243  [0]=>
244  int(0)
245  ["key"]=>
246  int(0)
247}
248Done