summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_rand.phpt
blob: 589572754829b9dc74c5b33fe4389983970bb1ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--TEST--
array_rand() tests
--FILE--
<?php

try {
    var_dump(array_rand(array()));
} catch (\Error $e) {
    echo $e->getMessage() . "\n";
}

try {
    var_dump(array_rand(array(), 0));
} catch (\Error $e) {
    echo $e->getMessage() . "\n";
}

try {
    var_dump(array_rand(array(1,2,3), 0));
} catch (\Error $e) {
    echo $e->getMessage() . "\n";
}

try {
    var_dump(array_rand(array(1,2,3), -1));
} catch (\Error $e) {
    echo $e->getMessage() . "\n";
}

try {
    var_dump(array_rand(array(1,2,3), 10));
} catch (\Error $e) {
    echo $e->getMessage() . "\n";
}

var_dump(array_rand(array(1,2,3), 3));
var_dump(array_rand(array(1,2,3), 2));

echo "Done\n";
?>
--EXPECTF--
Array is empty
Array is empty
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
array(3) {
  [0]=>
  int(%d)
  [1]=>
  int(%d)
  [2]=>
  int(%d)
}
array(2) {
  [0]=>
  int(%d)
  [1]=>
  int(%d)
}
Done