1--TEST--
2Test krsort() function : usage variations - sort array with/without key values
3--FILE--
4<?php
5/*
6 * Testing krsort() by providing arrays  with/without key values for $array argument
7 * with following flag values:
8 *  1.flag value as default
9 *  2.SORT_REGULAR - compare items normally
10 */
11
12echo "*** Testing krsort() : usage variations ***\n";
13
14// list of arrays with/without key values
15$various_arrays = array (
16  array(5 => 55,  66, 22, 33, 11),
17  array ("a" => "orange",  "banana", "c" => "apple"),
18  array(1, 2, 3, 4, 5, 6),
19  array("first", 5 => "second", 1 => "third"),
20  array(1, 1, 8 => 1,  4 => 1, 19, 3 => 13),
21  array('bar' => 'baz', "foo" => 1),
22  array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5),
23);
24
25$count = 1;
26echo "\n-- Testing krsort() by supplying various arrays with/without key values --\n";
27
28// loop through to test krsort() with different arrays,
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( krsort($temp_array) );
35  var_dump($temp_array);
36
37  echo "- Sort flag = SORT_REGULAR -\n";
38  $temp_array = $array;
39  var_dump( krsort($temp_array, SORT_REGULAR) );
40  var_dump($temp_array);
41  $count++;
42}
43
44echo "Done\n";
45?>
46--EXPECT--
47*** Testing krsort() : usage variations ***
48
49-- Testing krsort() by supplying various arrays with/without key values --
50
51-- Iteration 1 --
52- With default sort flag -
53bool(true)
54array(5) {
55  [9]=>
56  int(11)
57  [8]=>
58  int(33)
59  [7]=>
60  int(22)
61  [6]=>
62  int(66)
63  [5]=>
64  int(55)
65}
66- Sort flag = SORT_REGULAR -
67bool(true)
68array(5) {
69  [9]=>
70  int(11)
71  [8]=>
72  int(33)
73  [7]=>
74  int(22)
75  [6]=>
76  int(66)
77  [5]=>
78  int(55)
79}
80
81-- Iteration 2 --
82- With default sort flag -
83bool(true)
84array(3) {
85  ["c"]=>
86  string(5) "apple"
87  ["a"]=>
88  string(6) "orange"
89  [0]=>
90  string(6) "banana"
91}
92- Sort flag = SORT_REGULAR -
93bool(true)
94array(3) {
95  ["c"]=>
96  string(5) "apple"
97  ["a"]=>
98  string(6) "orange"
99  [0]=>
100  string(6) "banana"
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  [5]=>
142  string(6) "second"
143  [1]=>
144  string(5) "third"
145  [0]=>
146  string(5) "first"
147}
148- Sort flag = SORT_REGULAR -
149bool(true)
150array(3) {
151  [5]=>
152  string(6) "second"
153  [1]=>
154  string(5) "third"
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  [8]=>
166  int(1)
167  [4]=>
168  int(1)
169  [3]=>
170  int(13)
171  [1]=>
172  int(1)
173  [0]=>
174  int(1)
175}
176- Sort flag = SORT_REGULAR -
177bool(true)
178array(6) {
179  [9]=>
180  int(19)
181  [8]=>
182  int(1)
183  [4]=>
184  int(1)
185  [3]=>
186  int(13)
187  [1]=>
188  int(1)
189  [0]=>
190  int(1)
191}
192
193-- Iteration 6 --
194- With default sort flag -
195bool(true)
196array(2) {
197  ["foo"]=>
198  int(1)
199  ["bar"]=>
200  string(3) "baz"
201}
202- Sort flag = SORT_REGULAR -
203bool(true)
204array(2) {
205  ["foo"]=>
206  int(1)
207  ["bar"]=>
208  string(3) "baz"
209}
210
211-- Iteration 7 --
212- With default sort flag -
213bool(true)
214array(4) {
215  ["d"]=>
216  int(5)
217  ["c"]=>
218  array(1) {
219    ["g"]=>
220    int(4)
221  }
222  ["b"]=>
223  array(2) {
224    ["e"]=>
225    int(2)
226    ["f"]=>
227    int(3)
228  }
229  ["a"]=>
230  int(1)
231}
232- Sort flag = SORT_REGULAR -
233bool(true)
234array(4) {
235  ["d"]=>
236  int(5)
237  ["c"]=>
238  array(1) {
239    ["g"]=>
240    int(4)
241  }
242  ["b"]=>
243  array(2) {
244    ["e"]=>
245    int(2)
246    ["f"]=>
247    int(3)
248  }
249  ["a"]=>
250  int(1)
251}
252Done
253