1--TEST--
2Test shuffle() function : usage variation - arrays with diff types of values
3--FILE--
4<?php
5/* Prototype  : bool shuffle(array $array_arg)
6 * Description: Randomly shuffle the contents of an array
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Test behaviour of shuffle() function when arrays having different
12* types of values, are passed to 'array_arg' argument
13*/
14
15echo "*** Testing shuffle() : arrays with diff types of values ***\n";
16
17// initialise different arrays
18$array_arg = array(
19       // array with positive int values
20/*1*/  array(0, 1, 2, 2147483647 ),
21
22       // array with negative int values
23       array(-1, -2, -2147483647 ),
24
25       // array with positive float values
26/*3*/  array(0.23, 1.34, 0e2, 200e-2, 30e2, 10e0, 2147473648.90),
27
28       // array with negative float values
29       array(-0.23, -1.34, -200e-2, -30e2, -10e0, -2147473649.80),
30
31       // array with single quoted and double quoted strings
32/*5*/  array('one', "123numbers", 'hello\tworld', "hello world\0", '12.34floatnum'),
33
34       // array with bool values
35       array(true, TRUE, FALSE, false),
36
37       // array with positive hexa values
38/*7*/  array(0x123, 0xabc, 0xABC, 0xac, 0xAb1, 0x9fa),
39
40       // array with negative hexa values
41       array(-0x123, -0xabc, -0xABC, -0xAb1, -0x9fa),
42
43       // array with positive octal values
44/*9*/  array(0123, 02348, 034, 00),
45
46       // array with negative octal values
47/*10*/ array(-0123, -02348, -034),
48
49);
50
51// looping to test shuffle() with each sub-array in the $array_arg array
52echo "\n*** Testing shuffle() with arrays having different types of values ***\n";
53$counter = 1;
54foreach($array_arg as $arr) {
55  echo "\n-- Iteration $counter --\n";
56  var_dump( shuffle($arr) );
57  echo "\nThe output array is:\n";
58  var_dump( $arr );
59  $counter++;
60}
61
62echo "Done";
63?>
64--EXPECTF--
65*** Testing shuffle() : arrays with diff types of values ***
66
67*** Testing shuffle() with arrays having different types of values ***
68
69-- Iteration 1 --
70bool(true)
71
72The output array is:
73array(4) {
74  [0]=>
75  int(%d)
76  [1]=>
77  int(%d)
78  [2]=>
79  int(%d)
80  [3]=>
81  int(%d)
82}
83
84-- Iteration 2 --
85bool(true)
86
87The output array is:
88array(3) {
89  [0]=>
90  int(-%d)
91  [1]=>
92  int(-%d)
93  [2]=>
94  int(-%d)
95}
96
97-- Iteration 3 --
98bool(true)
99
100The output array is:
101array(7) {
102  [0]=>
103  float(%f)
104  [1]=>
105  float(%f)
106  [2]=>
107  float(%f)
108  [3]=>
109  float(%f)
110  [4]=>
111  float(%f)
112  [5]=>
113  float(%f)
114  [6]=>
115  float(%f)
116}
117
118-- Iteration 4 --
119bool(true)
120
121The output array is:
122array(6) {
123  [0]=>
124  float(-%f)
125  [1]=>
126  float(-%f)
127  [2]=>
128  float(-%f)
129  [3]=>
130  float(-%f)
131  [4]=>
132  float(-%f)
133  [5]=>
134  float(-%f)
135}
136
137-- Iteration 5 --
138bool(true)
139
140The output array is:
141array(5) {
142  [0]=>
143  string(%d) "%s"
144  [1]=>
145  string(%d) "%s"
146  [2]=>
147  string(%d) "%s"
148  [3]=>
149  string(%d) "%s"
150  [4]=>
151  string(%d) "%s"
152}
153
154-- Iteration 6 --
155bool(true)
156
157The output array is:
158array(4) {
159  [0]=>
160  bool(%s)
161  [1]=>
162  bool(%s)
163  [2]=>
164  bool(%s)
165  [3]=>
166  bool(%s)
167}
168
169-- Iteration 7 --
170bool(true)
171
172The output array is:
173array(6) {
174  [0]=>
175  int(%d)
176  [1]=>
177  int(%d)
178  [2]=>
179  int(%d)
180  [3]=>
181  int(%d)
182  [4]=>
183  int(%d)
184  [5]=>
185  int(%d)
186}
187
188-- Iteration 8 --
189bool(true)
190
191The output array is:
192array(5) {
193  [0]=>
194  int(-%d)
195  [1]=>
196  int(-%d)
197  [2]=>
198  int(-%d)
199  [3]=>
200  int(-%d)
201  [4]=>
202  int(-%d)
203}
204
205-- Iteration 9 --
206bool(true)
207
208The output array is:
209array(4) {
210  [0]=>
211  int(%d)
212  [1]=>
213  int(%d)
214  [2]=>
215  int(%d)
216  [3]=>
217  int(%d)
218}
219
220-- Iteration 10 --
221bool(true)
222
223The output array is:
224array(3) {
225  [0]=>
226  int(-%d)
227  [1]=>
228  int(-%d)
229  [2]=>
230  int(-%d)
231}
232Done
233
234