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