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

PHP清空陣列函數

PHP清空陣列函數

pexelsphoto5555 unset(arrar) 將整個陣列清空,但之後如果再加入元素,其 ...

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

解決svchost.exe消...

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

Fatal error: Allowed memory size of 50331648 bytes exhausted (tried to allocate 12288 bytes) in

Fatal error: A...

今天在客戶的網站系統上發現了一個問題。 在上傳檔案時發生了一個錯誤: Fatal error: Al...

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