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

使用jQuery阻止input直接按Enter就送出表單

使用jQuery阻止inpu...

使用表單是傳送資料裡經常會用到的方式。 這時當使用者輸入表單後習慣上按下Enter,則會將表單內容送...

分享 不得不用的15個神奇熱鍵

分享 不得不用的15個神奇熱...

好吧~我學到了,看看有沒有機會用上。 我承認切換桌面跟把視窗快速隱藏的熱鍵是蠻好用的。 不想被發現的...

php使用PDO獲取結果的方法

php使用PDO獲取結果的方...

fetch() 式例如下: mixed PDOStatement::fetch([int fetch...

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