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