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

SQL Injection

SQL Injection

SELECT * FROM users WHERE user=&#;aidan&#;...

黑客松Hackathon

黑客松Hackathon

這個星期六日要同朋友去參加一個聚會...黑客松Hackathon... 老實說我根本不知道那是什麼....

在PHP裡面如何做到基本的SQL injection防禦?

在PHP裡面如何做到基本的S...

資訊安全一直是很頭痛的問題....我一直以來也在尋找最好的方式... 但在尋找的過程中...至少也得...

Recommended reading

Other stories happened at this address

解決png圖檔GD合圖後背景色塊問題

解決png圖檔GD合圖後背景...

重點在於設定圖片走透明通道~ $img = imagecreatefrompng($src); im...

小黃便利貼

小黃便利貼

news 小黃便利貼~是Innstory系統技術性介紹配置。 呈現的位置為版面左上角九宮格上方。 簡...

5G最近口水疹嚴重的很啊~心疼死了

5G最近口水疹嚴重的很啊~心...

G最近口水疹嚴重的很啊~心疼死了

5G餵食秀

5G餵食秀

餵食前,一刻也不能等,哭得我心慌意亂。 餵食後,笑中還帶著淚。 我知道妳要的很簡單,但也請妳多給我些...

笑起來,跟Mandy小時候一模一樣。

笑起來,跟Mandy小時候一...

笑起來,跟Mandy小時候一模一樣。

日常

日常

s 一整天跟U鬥體力。 好不容易,等到Mandy下班,晚上也哄兒子睡了。 收拾了凌亂的現場,雖說每天...

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