1--TEST--
2Test array_key_first() function
3--FILE--
4<?php
5
6array_key_first($GLOBALS);
7
8/* Various combinations of arrays to be used for the test */
9$mixed_array = array(
10  array(),
11  array( 1,2,3,4,5,6,7,8,9 ),
12  array( "One", "_Two", "Three", "Four", "Five" ),
13  array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ),
14  array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ),
15  array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ),
16  array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ),
17  array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF",
18         "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ),
19  array( 12, "name", 'age', '45' ),
20  array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ),
21  array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6,
22          5 => 57, "5.4" => 554, "5.7" => 557 ),
23  array( "foo" ),
24  array( 1 => "42" )
25);
26
27/* Loop to test normal functionality with different arrays inputs */
28echo "\n*** Normal testing with various array inputs ***\n";
29
30$counter = 1;
31foreach( $mixed_array as $sub_array )
32{
33 echo "\n-- Input Array for Iteration $counter is --\n";
34 var_dump( $sub_array );
35 echo "\nFirst key is :\n";
36 var_dump( array_key_first($sub_array) );
37 $counter++;
38}
39
40echo"\nDone";
41?>
42--EXPECT--
43*** Normal testing with various array inputs ***
44
45-- Input Array for Iteration 1 is --
46array(0) {
47}
48
49First key is :
50NULL
51
52-- Input Array for Iteration 2 is --
53array(9) {
54  [0]=>
55  int(1)
56  [1]=>
57  int(2)
58  [2]=>
59  int(3)
60  [3]=>
61  int(4)
62  [4]=>
63  int(5)
64  [5]=>
65  int(6)
66  [6]=>
67  int(7)
68  [7]=>
69  int(8)
70  [8]=>
71  int(9)
72}
73
74First key is :
75int(0)
76
77-- Input Array for Iteration 3 is --
78array(5) {
79  [0]=>
80  string(3) "One"
81  [1]=>
82  string(4) "_Two"
83  [2]=>
84  string(5) "Three"
85  [3]=>
86  string(4) "Four"
87  [4]=>
88  string(4) "Five"
89}
90
91First key is :
92int(0)
93
94-- Input Array for Iteration 4 is --
95array(8) {
96  [0]=>
97  int(6)
98  [1]=>
99  string(3) "six"
100  [2]=>
101  int(7)
102  [3]=>
103  string(5) "seven"
104  [4]=>
105  int(8)
106  [5]=>
107  string(5) "eight"
108  [6]=>
109  int(9)
110  [7]=>
111  string(4) "nine"
112}
113
114First key is :
115int(0)
116
117-- Input Array for Iteration 5 is --
118array(5) {
119  ["a"]=>
120  string(3) "aaa"
121  ["A"]=>
122  string(3) "AAA"
123  ["c"]=>
124  string(3) "ccc"
125  ["d"]=>
126  string(3) "ddd"
127  ["e"]=>
128  string(3) "eee"
129}
130
131First key is :
132string(1) "a"
133
134-- Input Array for Iteration 6 is --
135array(5) {
136  [1]=>
137  string(3) "one"
138  [2]=>
139  string(3) "two"
140  [3]=>
141  string(5) "three"
142  [4]=>
143  string(4) "four"
144  [5]=>
145  string(4) "five"
146}
147
148First key is :
149int(1)
150
151-- Input Array for Iteration 7 is --
152array(5) {
153  [1]=>
154  string(3) "one"
155  [2]=>
156  string(3) "two"
157  [3]=>
158  int(7)
159  [4]=>
160  string(4) "four"
161  [5]=>
162  string(4) "five"
163}
164
165First key is :
166int(1)
167
168-- Input Array for Iteration 8 is --
169array(12) {
170  ["f"]=>
171  string(3) "fff"
172  [1]=>
173  string(3) "one"
174  [4]=>
175  int(6)
176  [""]=>
177  int(3)
178  [2]=>
179  string(5) "float"
180  ["F"]=>
181  string(3) "FFF"
182  ["blank"]=>
183  string(0) ""
184  [3]=>
185  float(3.7)
186  [5]=>
187  string(4) "Five"
188  [6]=>
189  float(8.6)
190  ["4name"]=>
191  string(5) "jonny"
192  ["a"]=>
193  NULL
194}
195
196First key is :
197string(1) "f"
198
199-- Input Array for Iteration 9 is --
200array(4) {
201  [0]=>
202  int(12)
203  [1]=>
204  string(4) "name"
205  [2]=>
206  string(3) "age"
207  [3]=>
208  string(2) "45"
209}
210
211First key is :
212int(0)
213
214-- Input Array for Iteration 10 is --
215array(3) {
216  [0]=>
217  array(3) {
218    [0]=>
219    string(3) "oNe"
220    [1]=>
221    string(3) "tWo"
222    [2]=>
223    int(4)
224  }
225  [1]=>
226  array(5) {
227    [0]=>
228    int(10)
229    [1]=>
230    int(20)
231    [2]=>
232    int(30)
233    [3]=>
234    int(40)
235    [4]=>
236    int(50)
237  }
238  [2]=>
239  array(0) {
240  }
241}
242
243First key is :
244int(0)
245
246-- Input Array for Iteration 11 is --
247array(10) {
248  ["one"]=>
249  int(2)
250  ["three"]=>
251  int(3)
252  [0]=>
253  int(3)
254  [1]=>
255  int(4)
256  [3]=>
257  int(33)
258  [4]=>
259  int(44)
260  [5]=>
261  int(57)
262  [6]=>
263  int(6)
264  ["5.4"]=>
265  int(554)
266  ["5.7"]=>
267  int(557)
268}
269
270First key is :
271string(3) "one"
272
273-- Input Array for Iteration 12 is --
274array(1) {
275  [0]=>
276  string(3) "foo"
277}
278
279First key is :
280int(0)
281
282-- Input Array for Iteration 13 is --
283array(1) {
284  [1]=>
285  string(2) "42"
286}
287
288First key is :
289int(1)
290
291Done
292