Annotation of embedaddon/php/ext/standard/tests/array/array_rand_basic2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_rand() function : basic functionality - with associative array for 'input' argument
3: --FILE--
4: <?php
5: /* Prototype : mixed array_rand(array $input [, int $num_req])
6: * Description: Return key/keys for random entry/entries in the array
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Test array_rand() when associative array is passed to 'input' argument
12: */
13:
14: echo "*** Testing array_rand() : with associative array ***\n";
15:
16:
17: // Initialise the 'input' and 'num_req' variables
18: $input = array(
19: 'one' => 1, 'two' => 2, 'three' => 3,
20: 'FoUr' => 'four', '#5' => 5, 'SIX' => 'six',
21: "seven" => 7, "#8" => "eight", "nine" => "NINE"
22: );
23:
24: $num_req = 6;
25:
26: // Calling array_rand() with optional argument
27: echo"\n-- with all default and optional arguments --\n";
28: var_dump( array_rand($input,$num_req) );
29:
30: // Calling array_rand() with default arguments
31: echo"\n-- with default argument --\n";
32: var_dump( array_rand($input) );
33:
34: echo "Done";
35: ?>
36: --EXPECTF--
37: *** Testing array_rand() : with associative array ***
38:
39: -- with all default and optional arguments --
40: array(6) {
41: [0]=>
42: string(%d) "%s"
43: [1]=>
44: string(%d) "%s"
45: [2]=>
46: string(%d) "%s"
47: [3]=>
48: string(%d) "%s"
49: [4]=>
50: string(%d) "%s"
51: [5]=>
52: string(%d) "%s"
53: }
54:
55: -- with default argument --
56: string(%d) "%s"
57: Done
58:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>