mirror of
https://github.com/php/php-src.git
synced 2026-03-25 08:42:29 +01:00
This is targeting 8.0. `$arg` seems like a poor choice of a name, especially if the function were to have arguments added. In many cases, the php.net documentation already has $array for these functions. E.g. https://www.php.net/manual/en/function.array-intersect.php I'd assume that since named arguments was added to 8.0 near the feature freeze, PHP's maintainers had planned to make the names consistent and gradually use the same name for docs and implementation.
60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
--TEST--
|
|
array_rand() tests
|
|
--FILE--
|
|
<?php
|
|
|
|
try {
|
|
var_dump(array_rand(array()));
|
|
} catch (\ValueError $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
var_dump(array_rand(array(), 0));
|
|
} catch (\ValueError $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
var_dump(array_rand(array(1,2,3), 0));
|
|
} catch (\ValueError $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
var_dump(array_rand(array(1,2,3), -1));
|
|
} catch (\ValueError $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
var_dump(array_rand(array(1,2,3), 10));
|
|
} catch (\ValueError $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
var_dump(array_rand(array(1,2,3), 3));
|
|
var_dump(array_rand(array(1,2,3), 2));
|
|
|
|
?>
|
|
--EXPECTF--
|
|
array_rand(): Argument #1 ($array) cannot be empty
|
|
array_rand(): Argument #1 ($array) cannot be empty
|
|
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($array)
|
|
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($array)
|
|
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($array)
|
|
array(3) {
|
|
[0]=>
|
|
int(%d)
|
|
[1]=>
|
|
int(%d)
|
|
[2]=>
|
|
int(%d)
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
int(%d)
|
|
[1]=>
|
|
int(%d)
|
|
}
|