在 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 )
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP