Return to shuffle_basic2.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test 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: 17: echo "*** 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 27: echo "\n-- input array before shuffle() function is applied --\n"; 28: var_dump( $array_arg ); 29: 30: // applying shuffle() function on the input array 31: echo "\n-- return value from shuffle() function --\n"; 32: var_dump( shuffle($array_arg) ); // prints the return value from shuffle() function 33: 34: echo "\n-- resultant array after shuffle() function is applied --\n"; 35: var_dump( $array_arg ); 36: 37: echo "Done"; 38: ?> 39: --EXPECTF-- 40: *** Testing shuffle() : with associative array *** 41: 42: -- input array before shuffle() function is applied -- 43: array(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 -- 65: bool(true) 66: 67: -- resultant array after shuffle() function is applied -- 68: array(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: } 88: Done 89: