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