在 PHP 中生成隨機唯一數字陣列?


對於隨機唯一數字陣列,請將 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 )

更新於: 2020 年 10 月 13 日

805 次瀏覽

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.