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