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