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       // null data
32/*4*/  'null uppercase' => array(
33       NULL => 'null 1',
34       ),
35
36/*5*/  'null lowercase' => array(
37       null => 'null 2',
38       ),
39
40       // boolean data
41/*6*/ 'bool lowercase' => array(
42       true => 'lowert',
43       false => 'lowerf',
44       ),
45
46/*7*/  'bool uppercase' => array(
47       TRUE => 'uppert',
48       FALSE => 'upperf',
49       ),
50
51       // empty data
52/*8*/ 'empty double quotes' => array(
53       "" => 'emptyd',
54       ),
55
56/*9*/  'empty single quotes' => array(
57       '' => 'emptys',
58       ),
59
60       // string data
61/*10*/ 'string' => array(
62       "stringd" => 'stringd',
63       'strings' => 'strings',
64       $heredoc => 'stringh',
65       ),
66
67       // undefined data
68/*11*/ 'undefined' => array(
69       @$undefined_var => 'undefined',
70       ),
71
72       // unset data
73/*12*/ 'unset' => array(
74       @$unset_var => 'unset',
75       ),
76
77       // duplicate values
78/*13*/ 'duplicate' => array(
79       'foo' => 'bar',
80       'baz' => 'bar',
81       'hello' => 'world'
82       ),
83
84);
85
86// loop through each element of $inputs to check the behavior of natcasesort()
87$iterator = 1;
88foreach($inputs as $input) {
89    echo "\n-- Iteration $iterator --\n";
90    var_dump( natcasesort($input) );
91    var_dump($input);
92    $iterator++;
93};
94
95echo "Done";
96?>
97--EXPECT--
98*** Testing natcasesort() : usage variations ***
99
100-- Iteration 1 --
101bool(true)
102array(4) {
103  [-2345]=>
104  string(8) "negative"
105  [1]=>
106  string(3) "one"
107  [12345]=>
108  string(8) "positive"
109  [0]=>
110  string(4) "zero"
111}
112
113-- Iteration 2 --
114bool(true)
115array(1) {
116  [""]=>
117  string(6) "null 1"
118}
119
120-- Iteration 3 --
121bool(true)
122array(1) {
123  [""]=>
124  string(6) "null 2"
125}
126
127-- Iteration 4 --
128bool(true)
129array(2) {
130  [0]=>
131  string(6) "lowerf"
132  [1]=>
133  string(6) "lowert"
134}
135
136-- Iteration 5 --
137bool(true)
138array(2) {
139  [0]=>
140  string(6) "upperf"
141  [1]=>
142  string(6) "uppert"
143}
144
145-- Iteration 6 --
146bool(true)
147array(1) {
148  [""]=>
149  string(6) "emptyd"
150}
151
152-- Iteration 7 --
153bool(true)
154array(1) {
155  [""]=>
156  string(6) "emptys"
157}
158
159-- Iteration 8 --
160bool(true)
161array(3) {
162  ["stringd"]=>
163  string(7) "stringd"
164  ["hello world"]=>
165  string(7) "stringh"
166  ["strings"]=>
167  string(7) "strings"
168}
169
170-- Iteration 9 --
171bool(true)
172array(1) {
173  [""]=>
174  string(9) "undefined"
175}
176
177-- Iteration 10 --
178bool(true)
179array(1) {
180  [""]=>
181  string(5) "unset"
182}
183
184-- Iteration 11 --
185bool(true)
186array(3) {
187  ["foo"]=>
188  string(3) "bar"
189  ["baz"]=>
190  string(3) "bar"
191  ["hello"]=>
192  string(5) "world"
193}
194Done
195