1--TEST--
2array_rand() tests
3--FILE--
4<?php
5
6try {
7    var_dump(array_rand(array()));
8} catch (\ValueError $e) {
9    echo $e->getMessage() . "\n";
10}
11
12try {
13    var_dump(array_rand(array(), 0));
14} catch (\ValueError $e) {
15    echo $e->getMessage() . "\n";
16}
17
18try {
19    var_dump(array_rand(array(1,2,3), 0));
20} catch (\ValueError $e) {
21    echo $e->getMessage() . "\n";
22}
23
24try {
25    var_dump(array_rand(array(1,2,3), -1));
26} catch (\ValueError $e) {
27    echo $e->getMessage() . "\n";
28}
29
30try {
31    var_dump(array_rand(array(1,2,3), 10));
32} catch (\ValueError $e) {
33    echo $e->getMessage() . "\n";
34}
35
36var_dump(array_rand(array(1,2,3), 3));
37var_dump(array_rand(array(1,2,3), 2));
38
39?>
40--EXPECTF--
41array_rand(): Argument #1 ($array) must not be empty
42array_rand(): Argument #1 ($array) must not be empty
43array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
44array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
45array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
46array(3) {
47  [0]=>
48  int(%d)
49  [1]=>
50  int(%d)
51  [2]=>
52  int(%d)
53}
54array(2) {
55  [0]=>
56  int(%d)
57  [1]=>
58  int(%d)
59}
60