1--TEST--
2Test shuffle() function : basic functionality - array with default keys
3--FILE--
4<?php
5/*
6* Test behaviour of shuffle when an array with default keys
7* is passed to the 'array_arg' argument and check for the
8* changes in the input array by printing the input array
9* before and after shuffle() function is applied on it
10*/
11
12echo "*** Testing shuffle() : with arrays having default keys ***\n";
13
14// Initialise the array with integers
15$array_arg_int = array(0, 10, 20, 30, 40, 50, 60, 70, 80);
16
17// Initialise the array with strings
18$array_arg_strings = array("one", 'two', 'three', "four", "five", " ", 'six', ' ', "seven");
19
20/* Testing shuffle() function with array of integers */
21
22// printing the input array with integers before the shuffle operation
23echo "\n-- input array of integers before shuffle() function is applied --\n";
24var_dump( $array_arg_int );
25
26// applying shuffle() function on the input array of integers
27echo "\n-- return value from shuffle() function --\n";
28var_dump( shuffle($array_arg_int) );  // prints the return value from shuffle() function
29
30echo "\n-- resultant array after shuffle() function is applied --\n";
31var_dump( $array_arg_int );
32
33/* Testing shuffle() function with array of strings */
34
35// printing the input array with strings before the shuffle operation
36echo "\n-- input array of strings before shuffle() function is applied --\n";
37var_dump( $array_arg_strings );
38
39// applying shuffle() function on the input array of strings
40echo "\n-- return value from shuffle() function --\n";
41var_dump( shuffle($array_arg_strings) );  // prints the return value from shuffle() function
42
43echo "\n-- resultant array after shuffle() function is applied --\n";
44var_dump( $array_arg_strings );
45
46echo "Done";
47?>
48--EXPECTF--
49*** Testing shuffle() : with arrays having default keys ***
50
51-- input array of integers before shuffle() function is applied --
52array(9) {
53  [0]=>
54  int(0)
55  [1]=>
56  int(10)
57  [2]=>
58  int(20)
59  [3]=>
60  int(30)
61  [4]=>
62  int(40)
63  [5]=>
64  int(50)
65  [6]=>
66  int(60)
67  [7]=>
68  int(70)
69  [8]=>
70  int(80)
71}
72
73-- return value from shuffle() function --
74bool(true)
75
76-- resultant array after shuffle() function is applied --
77array(9) {
78  [0]=>
79  int(%d)
80  [1]=>
81  int(%d)
82  [2]=>
83  int(%d)
84  [3]=>
85  int(%d)
86  [4]=>
87  int(%d)
88  [5]=>
89  int(%d)
90  [6]=>
91  int(%d)
92  [7]=>
93  int(%d)
94  [8]=>
95  int(%d)
96}
97
98-- input array of strings before shuffle() function is applied --
99array(9) {
100  [0]=>
101  string(3) "one"
102  [1]=>
103  string(3) "two"
104  [2]=>
105  string(5) "three"
106  [3]=>
107  string(4) "four"
108  [4]=>
109  string(4) "five"
110  [5]=>
111  string(1) " "
112  [6]=>
113  string(3) "six"
114  [7]=>
115  string(1) " "
116  [8]=>
117  string(5) "seven"
118}
119
120-- return value from shuffle() function --
121bool(true)
122
123-- resultant array after shuffle() function is applied --
124array(9) {
125  [0]=>
126  string(%d) "%s"
127  [1]=>
128  string(%d) "%s"
129  [2]=>
130  string(%d) "%s"
131  [3]=>
132  string(%d) "%s"
133  [4]=>
134  string(%d) "%s"
135  [5]=>
136  string(%d) "%s"
137  [6]=>
138  string(%d) "%s"
139  [7]=>
140  string(%d) "%s"
141  [8]=>
142  string(%d) "%s"
143}
144Done
145