PHP shuffle() 函數(shù)把數(shù)組中的元素按隨機(jī)順序重新排列。
php shuffle()函數(shù) 語(yǔ)法
作用:把數(shù)組中的元素按隨機(jī)順序重新排序:
語(yǔ)法:
shuffle(array)
參數(shù):
array 必需。規(guī)定要使用的數(shù)組。
說(shuō)明:若成功則返回 TRUE,若失敗則返回 FALSE。
php shuffle()函數(shù) 示例1:
- <?php
- $a = array("class" => "php中文網(wǎng)","name" => "西門","job" => "講師");
- shuffle($a);
- print_r($a);
- ?>
輸出:
Array ( [0] => 西門 [1] => php中文網(wǎng) [2] => 講師 )
php shuffle()函數(shù) 示例2:
- <?php
- $my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");
- shuffle($my_array);
- print_r($my_array);
- ?>
輸出:
Array ( [0] => yellow [1] => green [2] => red [3] => purple [4] => blue )
本篇文章就是關(guān)于PHP shuffle函數(shù)的介紹,希望對(duì)需要的朋友有所幫助!
以上就是shuffle函數(shù)怎么用的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
新聞熱點(diǎn)
疑難解答