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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
--TEST--
Test shuffle() function : basic functionality - array with default keys
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle when an array with default keys
* is passed to the 'array_arg' argument and check for the
* changes in the input array by printing the input array
* before and after shuffle() function is applied on it
*/
echo "*** Testing shuffle() : with arrays having default keys ***\n";
// Initialise the array with integers
$array_arg_int = array(0, 10, 20, 30, 40, 50, 60, 70, 80);
// Initialise the array with strings
$array_arg_strings = array("one", 'two', 'three', "four", "five", " ", 'six', ' ', "seven");
/* Testing shuffle() function with array of integers */
// printing the input array with integers before the shuffle operation
echo "\n-- input array of integers before shuffle() function is applied --\n";
var_dump( $array_arg_int );
// applying shuffle() function on the input array of integers
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_int) ); // prints the return value from shuffle() function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_int );
/* Testing shuffle() function with array of strings */
// printing the input array with strings before the shuffle operation
echo "\n-- input array of strings before shuffle() function is applied --\n";
var_dump( $array_arg_strings );
// applying shuffle() function on the input array of strings
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_strings) ); // prints the return value from shuffle() function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_strings );
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with arrays having default keys ***
-- input array of integers before shuffle() function is applied --
array(9) {
[0]=>
int(0)
[1]=>
int(10)
[2]=>
int(20)
[3]=>
int(30)
[4]=>
int(40)
[5]=>
int(50)
[6]=>
int(60)
[7]=>
int(70)
[8]=>
int(80)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
-- input array of strings before shuffle() function is applied --
array(9) {
[0]=>
string(3) "one"
[1]=>
string(3) "two"
[2]=>
string(5) "three"
[3]=>
string(4) "four"
[4]=>
string(4) "five"
[5]=>
string(1) " "
[6]=>
string(3) "six"
[7]=>
string(1) " "
[8]=>
string(5) "seven"
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
[2]=>
string(%d) "%s"
[3]=>
string(%d) "%s"
[4]=>
string(%d) "%s"
[5]=>
string(%d) "%s"
[6]=>
string(%d) "%s"
[7]=>
string(%d) "%s"
[8]=>
string(%d) "%s"
}
Done
--UEXPECTF--
*** Testing shuffle() : with arrays having default keys ***
-- input array of integers before shuffle() function is applied --
array(9) {
[0]=>
int(0)
[1]=>
int(10)
[2]=>
int(20)
[3]=>
int(30)
[4]=>
int(40)
[5]=>
int(50)
[6]=>
int(60)
[7]=>
int(70)
[8]=>
int(80)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
-- input array of strings before shuffle() function is applied --
array(9) {
[0]=>
unicode(3) "one"
[1]=>
unicode(3) "two"
[2]=>
unicode(5) "three"
[3]=>
unicode(4) "four"
[4]=>
unicode(4) "five"
[5]=>
unicode(1) " "
[6]=>
unicode(3) "six"
[7]=>
unicode(1) " "
[8]=>
unicode(5) "seven"
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
unicode(%d) "%s"
[1]=>
unicode(%d) "%s"
[2]=>
unicode(%d) "%s"
[3]=>
unicode(%d) "%s"
[4]=>
unicode(%d) "%s"
[5]=>
unicode(%d) "%s"
[6]=>
unicode(%d) "%s"
[7]=>
unicode(%d) "%s"
[8]=>
unicode(%d) "%s"
}
Done
|