Loading...

PHP重新排列陣列中的元素shuffle()函數

Temperature: 0 °C

Mark ChangMark Chang
author_tools

shuffle() 是可以將陣列中元素的順序重新洗牌的函數。
甚麼時候用的到?
例如最近寫著一個抽獎機制,共有10組得獎這邊先設定為YES,10組未得獎的元素這邊先設定為NO。
而他在陣列中排列的方式為:

$array = array("YES","YES","YES","YES","YES","YES","YES","YES","YES","YES","NO","NO","NO","NO","NO","NO","NO","NO","NO","NO");

當使用shuffle()重新排列時,將會隨機呈現如下:
$array = array("YES","NO","YES","NO","NO","YES","YES","YES","NO","YES","NO","YES","NO","NO","YES","NO","YES","NO","YES","NO");

再來搭配機率來取得中獎。

以上紀錄~
 

#故事  #PHP  #shuffle  #重新洗牌  
https://innstory.com/story-PHP重新排列陣列中的元素shuffle函數-2997
PHP

Prev
 要如何修改Plesk空間上傳檔案大小的限制

Next
js判斷字母是否為大小寫 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

解決svchost.exe消耗記憶體問題

解決svchost.exe消...

pexelsphotowin55 根據微軟中文知識庫編號5的文件說明:「SVCHOST.EXE是從動...

當域名 DNS 尚未生效時,如何預先設定及測試網站

當域名 DNS 尚未生效時,...

建置一個新的網站或是將網站搬家時 常常會遇到一個問題,就是要將網址指向到新的網站空間,設定完畢但需要...

使用CSS 讓ul li 橫向水平

使用CSS 讓ul li 橫...

好吧,其實這個css常在用,但我每次都沒特別紀錄,然後每次又忘記然後又要Google。 其實主要就是...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format