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