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