1--TEST--
2Test ksort() function : usage variations - sort strings
3--FILE--
4<?php
5/*
6 * testing ksort() by providing array of string values for $array argument with
7 * following flag values:
8 *  1.flag value as default
9 *  2.SORT_REGULAR - compare items normally
10 *  3.SORT_STRING  - compare items as strings
11*/
12
13echo "*** Testing ksort() : usage variations ***\n";
14
15$various_arrays = array (
16  // diff. escape sequence chars with key values
17  array ( null =>  null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e",
18          "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh",
19          "\ddd" => "\ddd", "\v" => "\v"
20        ),
21
22  // array containing different strings with key values
23  array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test",
24          't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe",
25          'B' => "BANANA"
26        )
27);
28
29$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
30
31$count = 1;
32echo "\n-- Testing ksort() by supplying various string arrays --\n";
33
34// loop through to test ksort() with different arrays
35foreach ($various_arrays as $array) {
36  echo "\n-- Iteration $count --\n";
37
38  echo "- With default sort flag -\n";
39  $temp_array = $array;
40  var_dump(ksort($temp_array) ); // expecting : bool(true)
41  var_dump($temp_array);
42
43  // loop through $flags array and call ksort() with all possible sort flag values
44  foreach($flags as $key => $flag){
45    echo "- Sort flag = $key -\n";
46    $temp_array = $array;
47    var_dump(ksort($temp_array, $flag) ); // expecting : bool(true)
48    var_dump($temp_array);
49  }
50  $count++;
51}
52
53echo "Done\n";
54?>
55--EXPECT--
56*** Testing ksort() : usage variations ***
57
58-- Testing ksort() by supplying various string arrays --
59
60-- Iteration 1 --
61- With default sort flag -
62bool(true)
63array(11) {
64  [""]=>
65  NULL
66  ["	"]=>
67  string(1) "	"
68  ["
69"]=>
70  string(1) "
71"
72  [""]=>
73  string(1) ""
74  [""]=>
75  string(1) ""
76  ["
76"]=>
77  string(1) "
77"
78  [""]=>
79  string(1) ""
80  ["\a"]=>
81  string(2) "\a"
82  ["\cx"]=>
83  string(3) "\cx"
84  ["\ddd"]=>
85  string(4) "\ddd"
86  ["\xhh"]=>
87  string(4) "\xhh"
88}
89- Sort flag = SORT_REGULAR -
90bool(true)
91array(11) {
92  [""]=>
93  NULL
94  ["	"]=>
95  string(1) "	"
96  ["
97"]=>
98  string(1) "
99"
100  [""]=>
101  string(1) ""
102  [""]=>
103  string(1) ""
104  ["
104"]=>
105  string(1) "
105"
106  [""]=>
107  string(1) ""
108  ["\a"]=>
109  string(2) "\a"
110  ["\cx"]=>
111  string(3) "\cx"
112  ["\ddd"]=>
113  string(4) "\ddd"
114  ["\xhh"]=>
115  string(4) "\xhh"
116}
117- Sort flag = SORT_STRING -
118bool(true)
119array(11) {
120  [""]=>
121  NULL
122  ["	"]=>
123  string(1) "	"
124  ["
125"]=>
126  string(1) "
127"
128  [""]=>
129  string(1) ""
130  [""]=>
131  string(1) ""
132  ["
132"]=>
133  string(1) "
133"
134  [""]=>
135  string(1) ""
136  ["\a"]=>
137  string(2) "\a"
138  ["\cx"]=>
139  string(3) "\cx"
140  ["\ddd"]=>
141  string(4) "\ddd"
142  ["\xhh"]=>
143  string(4) "\xhh"
144}
145
146-- Iteration 2 --
147- With default sort flag -
148bool(true)
149array(11) {
150  ["Apple"]=>
151  string(5) "apple"
152  ["B"]=>
153  string(6) "BANANA"
154  ["Lemon"]=>
155  string(5) "lemoN"
156  ["O"]=>
157  string(6) "oraNGe"
158  ["T"]=>
159  string(3) "ttt"
160  ["W"]=>
161  string(2) "ww"
162  ["X"]=>
163  string(1) "x"
164  ["o"]=>
165  string(6) "Orange"
166  ["t"]=>
167  string(4) "TTTT"
168  ["te"]=>
169  string(4) "Test"
170  ["x"]=>
171  string(1) "X"
172}
173- Sort flag = SORT_REGULAR -
174bool(true)
175array(11) {
176  ["Apple"]=>
177  string(5) "apple"
178  ["B"]=>
179  string(6) "BANANA"
180  ["Lemon"]=>
181  string(5) "lemoN"
182  ["O"]=>
183  string(6) "oraNGe"
184  ["T"]=>
185  string(3) "ttt"
186  ["W"]=>
187  string(2) "ww"
188  ["X"]=>
189  string(1) "x"
190  ["o"]=>
191  string(6) "Orange"
192  ["t"]=>
193  string(4) "TTTT"
194  ["te"]=>
195  string(4) "Test"
196  ["x"]=>
197  string(1) "X"
198}
199- Sort flag = SORT_STRING -
200bool(true)
201array(11) {
202  ["Apple"]=>
203  string(5) "apple"
204  ["B"]=>
205  string(6) "BANANA"
206  ["Lemon"]=>
207  string(5) "lemoN"
208  ["O"]=>
209  string(6) "oraNGe"
210  ["T"]=>
211  string(3) "ttt"
212  ["W"]=>
213  string(2) "ww"
214  ["X"]=>
215  string(1) "x"
216  ["o"]=>
217  string(6) "Orange"
218  ["t"]=>
219  string(4) "TTTT"
220  ["te"]=>
221  string(4) "Test"
222  ["x"]=>
223  string(1) "X"
224}
225Done
226