1--TEST--
2Test shuffle() function : usage variation - with MultiDimensional array
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 multi-dimensional array is
12* passed to 'array_arg' argument
13*/
14
15echo "*** Testing shuffle() : with multi-dimensional array ***\n";
16
17// initialise the multi-dimensional array
18$array_arg = array(
19  array(1, 2, 3),
20  array(4, 5, 6),
21  array(7, 8, 9),
22  array(10000, 20000000, 30000000),
23  array(0, 0, 0),
24  array(012, 023, 034),
25  array(0x1, 0x0, 0xa)
26
27);
28
29// calling shuffle() function with multi-dimensional array
30var_dump( shuffle($array_arg) );
31echo "\nThe output array is:\n";
32var_dump( $array_arg );
33
34
35// looping to test shuffle() with each sub-array in the multi-dimensional array
36echo "\n*** Testing shuffle() with arrays having different types of values ***\n";
37$counter = 1;
38for($i=0; $i<=6; $i++) {
39  echo "\n-- Iteration $counter --\n";
40  var_dump( shuffle($array_arg[$i]) );
41  echo "\nThe output array is:\n";
42  var_dump( $array_arg[$i] );
43  $counter++;
44}
45
46echo "Done";
47?>
48--EXPECTF--
49*** Testing shuffle() : with multi-dimensional array ***
50bool(true)
51
52The output array is:
53array(7) {
54  [0]=>
55  array(3) {
56    [0]=>
57    int(%d)
58    [1]=>
59    int(%d)
60    [2]=>
61    int(%d)
62  }
63  [1]=>
64  array(3) {
65    [0]=>
66    int(%d)
67    [1]=>
68    int(%d)
69    [2]=>
70    int(%d)
71  }
72  [2]=>
73  array(3) {
74    [0]=>
75    int(%d)
76    [1]=>
77    int(%d)
78    [2]=>
79    int(%d)
80  }
81  [3]=>
82  array(3) {
83    [0]=>
84    int(%d)
85    [1]=>
86    int(%d)
87    [2]=>
88    int(%d)
89  }
90  [4]=>
91  array(3) {
92    [0]=>
93    int(%d)
94    [1]=>
95    int(%d)
96    [2]=>
97    int(%d)
98  }
99  [5]=>
100  array(3) {
101    [0]=>
102    int(%d)
103    [1]=>
104    int(%d)
105    [2]=>
106    int(%d)
107  }
108  [6]=>
109  array(3) {
110    [0]=>
111    int(%d)
112    [1]=>
113    int(%d)
114    [2]=>
115    int(%d)
116  }
117}
118
119*** Testing shuffle() with arrays having different types of values ***
120
121-- Iteration 1 --
122bool(true)
123
124The output array is:
125array(3) {
126  [0]=>
127  int(%d)
128  [1]=>
129  int(%d)
130  [2]=>
131  int(%d)
132}
133
134-- Iteration 2 --
135bool(true)
136
137The output array is:
138array(3) {
139  [0]=>
140  int(%d)
141  [1]=>
142  int(%d)
143  [2]=>
144  int(%d)
145}
146
147-- Iteration 3 --
148bool(true)
149
150The output array is:
151array(3) {
152  [0]=>
153  int(%d)
154  [1]=>
155  int(%d)
156  [2]=>
157  int(%d)
158}
159
160-- Iteration 4 --
161bool(true)
162
163The output array is:
164array(3) {
165  [0]=>
166  int(%d)
167  [1]=>
168  int(%d)
169  [2]=>
170  int(%d)
171}
172
173-- Iteration 5 --
174bool(true)
175
176The output array is:
177array(3) {
178  [0]=>
179  int(%d)
180  [1]=>
181  int(%d)
182  [2]=>
183  int(%d)
184}
185
186-- Iteration 6 --
187bool(true)
188
189The output array is:
190array(3) {
191  [0]=>
192  int(%d)
193  [1]=>
194  int(%d)
195  [2]=>
196  int(%d)
197}
198
199-- Iteration 7 --
200bool(true)
201
202The output array is:
203array(3) {
204  [0]=>
205  int(%d)
206  [1]=>
207  int(%d)
208  [2]=>
209  int(%d)
210}
211Done
212