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.4 => "float", "F" => "FFF",
18         "blank" => "", 3.7 => 3.7, 5.4 => 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.4 => 54, 5.7 => 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 print_r( $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
47(
48)
49
50First key is :
51NULL
52
53-- Input Array for Iteration 2 is --
54Array
55(
56    [0] => 1
57    [1] => 2
58    [2] => 3
59    [3] => 4
60    [4] => 5
61    [5] => 6
62    [6] => 7
63    [7] => 8
64    [8] => 9
65)
66
67First key is :
68int(0)
69
70-- Input Array for Iteration 3 is --
71Array
72(
73    [0] => One
74    [1] => _Two
75    [2] => Three
76    [3] => Four
77    [4] => Five
78)
79
80First key is :
81int(0)
82
83-- Input Array for Iteration 4 is --
84Array
85(
86    [0] => 6
87    [1] => six
88    [2] => 7
89    [3] => seven
90    [4] => 8
91    [5] => eight
92    [6] => 9
93    [7] => nine
94)
95
96First key is :
97int(0)
98
99-- Input Array for Iteration 5 is --
100Array
101(
102    [a] => aaa
103    [A] => AAA
104    [c] => ccc
105    [d] => ddd
106    [e] => eee
107)
108
109First key is :
110string(1) "a"
111
112-- Input Array for Iteration 6 is --
113Array
114(
115    [1] => one
116    [2] => two
117    [3] => three
118    [4] => four
119    [5] => five
120)
121
122First key is :
123int(1)
124
125-- Input Array for Iteration 7 is --
126Array
127(
128    [1] => one
129    [2] => two
130    [3] => 7
131    [4] => four
132    [5] => five
133)
134
135First key is :
136int(1)
137
138-- Input Array for Iteration 8 is --
139Array
140(
141    [f] => fff
142    [1] => one
143    [4] => 6
144    [] => 3
145    [2] => float
146    [F] => FFF
147    [blank] =>
148    [3] => 3.7
149    [5] => Five
150    [6] => 8.6
151    [4name] => jonny
152    [a] =>
153)
154
155First key is :
156string(1) "f"
157
158-- Input Array for Iteration 9 is --
159Array
160(
161    [0] => 12
162    [1] => name
163    [2] => age
164    [3] => 45
165)
166
167First key is :
168int(0)
169
170-- Input Array for Iteration 10 is --
171Array
172(
173    [0] => Array
174        (
175            [0] => oNe
176            [1] => tWo
177            [2] => 4
178        )
179
180    [1] => Array
181        (
182            [0] => 10
183            [1] => 20
184            [2] => 30
185            [3] => 40
186            [4] => 50
187        )
188
189    [2] => Array
190        (
191        )
192
193)
194
195First key is :
196int(0)
197
198-- Input Array for Iteration 11 is --
199Array
200(
201    [one] => 2
202    [three] => 3
203    [0] => 3
204    [1] => 4
205    [3] => 33
206    [4] => 44
207    [5] => 57
208    [6] => 6
209    [5.4] => 554
210    [5.7] => 557
211)
212
213First key is :
214string(3) "one"
215
216-- Input Array for Iteration 12 is --
217Array
218(
219    [0] => foo
220)
221
222First key is :
223int(0)
224
225-- Input Array for Iteration 13 is --
226Array
227(
228    [1] => 42
229)
230
231First key is :
232int(1)
233
234Done
235