1--TEST--
2Test shuffle() function : basic functionality -  with associative 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 when an associative array is
12* passed to the 'array_arg' argument and check for the
13* changes in the input array by printing the input array
14* before and after shuffle() function is applied on it
15*/
16
17echo "*** Testing shuffle() : with associative array ***\n";
18
19// Initialise the associative array
20$array_arg = array(
21  'one' => 1, 2 => 02, 'three' => 3,
22   4 => 4, '#5' => 5, 'SIX' => 6,
23  "seven" => 0x7, "#8" => 012, "nine" => 9
24);
25
26// printing the input array before the shuffle operation
27echo "\n-- input array before shuffle() function is applied --\n";
28var_dump( $array_arg );
29
30// applying shuffle() function on the input array
31echo "\n-- return value from shuffle() function --\n";
32var_dump( shuffle($array_arg) );  // prints the return value from shuffle() function
33
34echo "\n-- resultant array after shuffle() function is applied --\n";
35var_dump( $array_arg );
36
37echo "Done";
38?>
39--EXPECTF--
40*** Testing shuffle() : with associative array ***
41
42-- input array before shuffle() function is applied --
43array(9) {
44  ["one"]=>
45  int(1)
46  [2]=>
47  int(2)
48  ["three"]=>
49  int(3)
50  [4]=>
51  int(4)
52  ["#5"]=>
53  int(5)
54  ["SIX"]=>
55  int(6)
56  ["seven"]=>
57  int(7)
58  ["#8"]=>
59  int(10)
60  ["nine"]=>
61  int(9)
62}
63
64-- return value from shuffle() function --
65bool(true)
66
67-- resultant array after shuffle() function is applied --
68array(9) {
69  [0]=>
70  int(%d)
71  [1]=>
72  int(%d)
73  [2]=>
74  int(%d)
75  [3]=>
76  int(%d)
77  [4]=>
78  int(%d)
79  [5]=>
80  int(%d)
81  [6]=>
82  int(%d)
83  [7]=>
84  int(%d)
85  [8]=>
86  int(%d)
87}
88Done
89