1--TEST--
2Test ksort() function : usage variations - sorting arrays with/without keys
3--FILE--
4<?php
5/*
6 * Testing ksort() by providing arrays  with/without key values for $array argument with following flag values:
7 *  1.flag value as default
8 *  2.SORT_REGULAR - compare items normally
9 */
10
11echo "*** Testing ksort() : usage variations ***\n";
12
13// list of arrays with/without key values
14$various_arrays = array (
15  array(5 => 55,  66, 22, 33, 11),
16  array ("a" => "orange",  "banana", "c" => "apple"),
17  array(1, 2, 3, 4, 5, 6),
18  array("first", 5 => "second", 1 => "third"),
19  array(1, 1, 8 => 1,  4 => 1, 19, 3 => 13),
20  array('bar' => 'baz', "foo" => 1),
21  array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5),
22);
23
24$count = 1;
25echo "\n-- Testing ksort() by supplying various arrays with/without key values --\n";
26
27// loop through to test ksort() with different arrays,
28foreach ($various_arrays as $array) {
29  echo "\n-- Iteration $count --\n";
30
31  echo "- With default sort flag -\n";
32  $temp_array = $array;
33  var_dump( ksort($temp_array) );
34  var_dump($temp_array);
35
36  echo "- Sort flag = SORT_REGULAR -\n";
37  $temp_array = $array;
38  var_dump( ksort($temp_array, SORT_REGULAR) );
39  var_dump($temp_array);
40  $count++;
41}
42
43echo "Done\n";
44?>
45--EXPECT--
46*** Testing ksort() : usage variations ***
47
48-- Testing ksort() by supplying various arrays with/without key values --
49
50-- Iteration 1 --
51- With default sort flag -
52bool(true)
53array(5) {
54  [5]=>
55  int(55)
56  [6]=>
57  int(66)
58  [7]=>
59  int(22)
60  [8]=>
61  int(33)
62  [9]=>
63  int(11)
64}
65- Sort flag = SORT_REGULAR -
66bool(true)
67array(5) {
68  [5]=>
69  int(55)
70  [6]=>
71  int(66)
72  [7]=>
73  int(22)
74  [8]=>
75  int(33)
76  [9]=>
77  int(11)
78}
79
80-- Iteration 2 --
81- With default sort flag -
82bool(true)
83array(3) {
84  [0]=>
85  string(6) "banana"
86  ["a"]=>
87  string(6) "orange"
88  ["c"]=>
89  string(5) "apple"
90}
91- Sort flag = SORT_REGULAR -
92bool(true)
93array(3) {
94  [0]=>
95  string(6) "banana"
96  ["a"]=>
97  string(6) "orange"
98  ["c"]=>
99  string(5) "apple"
100}
101
102-- Iteration 3 --
103- With default sort flag -
104bool(true)
105array(6) {
106  [0]=>
107  int(1)
108  [1]=>
109  int(2)
110  [2]=>
111  int(3)
112  [3]=>
113  int(4)
114  [4]=>
115  int(5)
116  [5]=>
117  int(6)
118}
119- Sort flag = SORT_REGULAR -
120bool(true)
121array(6) {
122  [0]=>
123  int(1)
124  [1]=>
125  int(2)
126  [2]=>
127  int(3)
128  [3]=>
129  int(4)
130  [4]=>
131  int(5)
132  [5]=>
133  int(6)
134}
135
136-- Iteration 4 --
137- With default sort flag -
138bool(true)
139array(3) {
140  [0]=>
141  string(5) "first"
142  [1]=>
143  string(5) "third"
144  [5]=>
145  string(6) "second"
146}
147- Sort flag = SORT_REGULAR -
148bool(true)
149array(3) {
150  [0]=>
151  string(5) "first"
152  [1]=>
153  string(5) "third"
154  [5]=>
155  string(6) "second"
156}
157
158-- Iteration 5 --
159- With default sort flag -
160bool(true)
161array(6) {
162  [0]=>
163  int(1)
164  [1]=>
165  int(1)
166  [3]=>
167  int(13)
168  [4]=>
169  int(1)
170  [8]=>
171  int(1)
172  [9]=>
173  int(19)
174}
175- Sort flag = SORT_REGULAR -
176bool(true)
177array(6) {
178  [0]=>
179  int(1)
180  [1]=>
181  int(1)
182  [3]=>
183  int(13)
184  [4]=>
185  int(1)
186  [8]=>
187  int(1)
188  [9]=>
189  int(19)
190}
191
192-- Iteration 6 --
193- With default sort flag -
194bool(true)
195array(2) {
196  ["bar"]=>
197  string(3) "baz"
198  ["foo"]=>
199  int(1)
200}
201- Sort flag = SORT_REGULAR -
202bool(true)
203array(2) {
204  ["bar"]=>
205  string(3) "baz"
206  ["foo"]=>
207  int(1)
208}
209
210-- Iteration 7 --
211- With default sort flag -
212bool(true)
213array(4) {
214  ["a"]=>
215  int(1)
216  ["b"]=>
217  array(2) {
218    ["e"]=>
219    int(2)
220    ["f"]=>
221    int(3)
222  }
223  ["c"]=>
224  array(1) {
225    ["g"]=>
226    int(4)
227  }
228  ["d"]=>
229  int(5)
230}
231- Sort flag = SORT_REGULAR -
232bool(true)
233array(4) {
234  ["a"]=>
235  int(1)
236  ["b"]=>
237  array(2) {
238    ["e"]=>
239    int(2)
240    ["f"]=>
241    int(3)
242  }
243  ["c"]=>
244  array(1) {
245    ["g"]=>
246    int(4)
247  }
248  ["d"]=>
249  int(5)
250}
251Done
252