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