1--TEST--
2Test rsort() function : usage variations - multi-dimensional 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() multi-dimensional arrays to test behaviour
12 */
13
14echo "*** Testing rsort() : variation ***\n";
15
16// array of arrays
17$various_arrays = array (
18  // null array
19  array(),
20
21  // array contains null sub array
22  array( array() ),
23
24  // array of arrays along with some values
25  array(44, 11, array(64, 61) ),
26
27  // array containing sub arrays
28  array(array(33, -5, 6), array(11), array(22, -55), array() )
29);
30
31
32$count = 1;
33
34// loop through to test rsort() with different arrays
35foreach ($various_arrays as $array) {
36
37  echo "\n-- Iteration $count --\n";
38
39  echo "\n-- 'flag' value is default --\n";
40  $temp_array = $array;
41  var_dump(rsort($temp_array) );
42  var_dump($temp_array);
43
44  echo "\n-- 'flag' value is SORT_REGULAR --\n";
45  $temp_array = $array;
46  var_dump(rsort($temp_array, SORT_REGULAR) );
47  var_dump($temp_array);
48  $count++;
49}
50
51echo "Done";
52?>
53
54--EXPECTF--
55*** Testing rsort() : variation ***
56
57-- Iteration 1 --
58
59-- 'flag' value is default --
60bool(true)
61array(0) {
62}
63
64-- 'flag' value is SORT_REGULAR --
65bool(true)
66array(0) {
67}
68
69-- Iteration 2 --
70
71-- 'flag' value is default --
72bool(true)
73array(1) {
74  [0]=>
75  array(0) {
76  }
77}
78
79-- 'flag' value is SORT_REGULAR --
80bool(true)
81array(1) {
82  [0]=>
83  array(0) {
84  }
85}
86
87-- Iteration 3 --
88
89-- 'flag' value is default --
90bool(true)
91array(3) {
92  [0]=>
93  array(2) {
94    [0]=>
95    int(64)
96    [1]=>
97    int(61)
98  }
99  [1]=>
100  int(44)
101  [2]=>
102  int(11)
103}
104
105-- 'flag' value is SORT_REGULAR --
106bool(true)
107array(3) {
108  [0]=>
109  array(2) {
110    [0]=>
111    int(64)
112    [1]=>
113    int(61)
114  }
115  [1]=>
116  int(44)
117  [2]=>
118  int(11)
119}
120
121-- Iteration 4 --
122
123-- 'flag' value is default --
124bool(true)
125array(4) {
126  [0]=>
127  array(3) {
128    [0]=>
129    int(33)
130    [1]=>
131    int(-5)
132    [2]=>
133    int(6)
134  }
135  [1]=>
136  array(2) {
137    [0]=>
138    int(22)
139    [1]=>
140    int(-55)
141  }
142  [2]=>
143  array(1) {
144    [0]=>
145    int(11)
146  }
147  [3]=>
148  array(0) {
149  }
150}
151
152-- 'flag' value is SORT_REGULAR --
153bool(true)
154array(4) {
155  [0]=>
156  array(3) {
157    [0]=>
158    int(33)
159    [1]=>
160    int(-5)
161    [2]=>
162    int(6)
163  }
164  [1]=>
165  array(2) {
166    [0]=>
167    int(22)
168    [1]=>
169    int(-55)
170  }
171  [2]=>
172  array(1) {
173    [0]=>
174    int(11)
175  }
176  [3]=>
177  array(0) {
178  }
179}
180Done