1--TEST--
2Test array_rand() function : usage variation - with heredoc string as key in the 'input' array
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 behaviour of array_rand() when keys of the 'input' array is heredoc string
12*/
13
14echo "*** Testing array_rand() : with keys of input array as heredoc strings ***\n";
15
16// defining different heredoc strings
17$empty_heredoc = <<<EOT
18EOT;
19
20$heredoc_with_newline = <<<EOT
21\n
22EOT;
23
24$heredoc_with_characters = <<<EOT
25first line of heredoc string
26second line of heredoc string
27third line of heredocstring
28EOT;
29
30$heredoc_with_newline_and_tabs = <<<EOT
31hello\tworld\nhello\nworld\n
32EOT;
33
34$heredoc_with_alphanumerics = <<<EOT
35hello123world456
361234hello\t1234
37EOT;
38
39$heredoc_with_embedded_nulls = <<<EOT
40hello\0world\0hello
41\0hello\0
42EOT;
43
44$input = array(
45  $empty_heredoc => "heredoc1",
46  $heredoc_with_newline => "heredoc2",
47  $heredoc_with_characters => "heredoc3",
48  $heredoc_with_newline_and_tabs => "heredoc3",
49  $heredoc_with_alphanumerics => "heredoc4",
50  $heredoc_with_embedded_nulls => "heredoc5"
51);
52
53// Test array_rand() function with different valid 'req_num' values
54echo "\n-- with default parameters --\n";
55var_dump( array_rand($input) );
56
57echo "\n-- with num_req = 1 --\n";
58var_dump( array_rand($input, 1) );
59
60echo "\n-- with num_req = 3 --\n";
61var_dump( array_rand($input, 3) );
62
63echo "\n-- with num_req = 6 --\n";
64var_dump( array_rand($input, 6) );
65
66
67echo "Done";
68?>
69--EXPECTREGEX--
70\*\*\* Testing array_rand\(\) : with keys of input array as heredoc strings \*\*\*
71
72-- with default parameters --
73string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
74
75-- with num_req = 1 --
76string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
77
78-- with num_req = 3 --
79array\(3\) {
80  \[0\]=>
81  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
82  \[1\]=>
83  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
84  \[2\]=>
85  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
86}
87
88-- with num_req = 6 --
89array\(6\) {
90  \[0\]=>
91  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
92  \[1\]=>
93  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
94  \[2\]=>
95  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
96  \[3\]=>
97  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
98  \[4\]=>
99  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
100  \[5\]=>
101  string\([0-9]*\) "[a-z \n \t \0 0-9  ]*"
102}
103Done
104