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