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

文件上傳過程中使用白名單、黑名單、或者MIME做認證

文件上傳過程中使用白名單、黑...

pexelsphotolock5 是不是被資安的問題搞得很煩? 我想,在建置系統的過程中,或多或少都...

Android UI設計距離課題

Android UI設計距離...

layoutmarginTop指定該屬性所在控件距離上方的位置空間。 layoutmarginBot...

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

解決svchost.exe消...

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

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