Annotation of embedaddon/php/ext/standard/tests/array/shuffle_basic1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
17: echo "*** 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
28: echo "\n-- input array of integers before shuffle() function is applied --\n";
29: var_dump( $array_arg_int );
30:
31: // applying shuffle() function on the input array of integers
32: echo "\n-- return value from shuffle() function --\n";
33: var_dump( shuffle($array_arg_int) ); // prints the return value from shuffle() function
34:
35: echo "\n-- resultant array after shuffle() function is applied --\n";
36: var_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
41: echo "\n-- input array of strings before shuffle() function is applied --\n";
42: var_dump( $array_arg_strings );
43:
44: // applying shuffle() function on the input array of strings
45: echo "\n-- return value from shuffle() function --\n";
46: var_dump( shuffle($array_arg_strings) ); // prints the return value from shuffle() function
47:
48: echo "\n-- resultant array after shuffle() function is applied --\n";
49: var_dump( $array_arg_strings );
50:
51: echo "Done";
52: ?>
53: --EXPECTF--
54: *** Testing shuffle() : with arrays having default keys ***
55:
56: -- input array of integers before shuffle() function is applied --
57: array(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 --
79: bool(true)
80:
81: -- resultant array after shuffle() function is applied --
82: array(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 --
104: array(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 --
126: bool(true)
127:
128: -- resultant array after shuffle() function is applied --
129: array(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: }
149: Done
150:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>