在 PHP 中生成随机唯一数字数组?

phpserver side programmingprogramming

对于随机唯一数字数组,请使用 range() 和 shuffle()。

示例

PHP 代码如下

<!DOCTYPE html>
<html>
<body>
<?php
$limit_random_array_values = range(10, 20);
shuffle($limit_random_array_values);
$all_five_random_array_value = array_slice($limit_random_array_values ,0,5);
print_r($all_five_random_array_value);
?>
</body>
</html>

输出

这将产生以下输出 −

Array ( [0] => 11 [1] => 14 [2] => 15 [3] => 12 [4] => 18 )

相关文章