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