Loading...

PHP 如何檢測陣列是否有重複值

Temperature: 0 °C

ChungChung
author_tools


PHP 如何檢測陣列是否有重複值
PHP陣列,是在coding時常用到的儲存資料的方式。

但,若陣列中的資料重複,在寫入資料庫時或許將會產生錯誤。

當然這得看當初的資料庫是如何規劃的? 

總之,若要檢查陣列資料是否有重複,使用了 PHP 提供的 array_unique 函數。

因為他可以把陣列中重複的資料做刪除的處理。

但,只是做刪除也不知道資料其實是重複了,這時當然還是得做個比對。

例如,比對使用前,跟使用後。化妝保養品也是這樣的比對方式( ̄∇ ̄)

$input = array($value1, $value2, $value3, $value4, $value5);//已知有5筆陣列資料
$input_unique = array_unique($input);//array_unique 處理中
if ( count($input) != count($input_unique) ){ //比對使用前使用後
echo "陣列中有重複資料!";
}

以上,心得紀錄。

台北市內湖區江南街71巷75弄 Go

https://innstory.com/story-PHP_如何檢測陣列是否有重複值-1374
寫程式筆記

Prev
 1歲5個月

Next
獨自一個人的2個星期最後幾個小時 

Nearby Attractions

台北市內湖區江南街71巷75弄-Nearby Attractions

  • 前南菜園日式宿舍 Go
  • 草山水道系統 Go
  • 草山御賓館 Go
  • 松山市場 Go
  • 國立臺北護理健康大學城區部文... Go
  • 臺大醫院舊館 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

校外教學(木柵動物園)

校外教學(木柵動物園)

期中考週的校外教學,來到了上回去不成的木柵動物園。 炎熱的天,帶著位小蘿蔔頭,一邊觀察一邊完成老師交...

Linux底下Apache啟動、停止、重啟指令

Linux底下Apache啟...

a5 如果apache安裝成為linux的服務的話,可以用以下命令操作: service httpd...

PHP網路爬蟲之抓取Open Graph(OG) Meta tags

PHP網路爬蟲之抓取Open...

用google爬了很多文章.... 最後終於找到一篇內容..... 只是測試了半天...感覺奇怪為何...

Recommended reading

Other stories happened at this address

看來我們家有好些日子可以充滿南洋風味~

看來我們家有好些日子可以充滿...

看來我們家有好些日子可以充滿南洋風味~

排列組合年紀~

排列組合年紀~

s 不知不覺的到了開始喜歡上排列組合遊戲的年紀。 總是把玩具或車車拿到某個角落空間。 然後開始堆疊起...

querySelectorAll對多個相同ID做統一處理

querySelectorA...

a 範例,想將同一組ID的DIV做統一隱藏的動作 var elms = document.query...

已經可以撐那麼高囉,撐住啊5U。

已經可以撐那麼高囉,撐住啊5...

已經可以撐那麼高囉,撐住啊U。

媽媽。。。。美麗

媽媽。。。。美麗

我想記住我在兒子心目中美麗的模樣,而發出的童言贊賞,所以難得的寫下這篇文章作爲記憶。 某天上班天的早...

果然還是紅白機對了胃口~

果然還是紅白機對了胃口~

果然還是紅白機對了胃口~

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