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

PDO連接Mysql方式 MVC上應用

PDO連接Mysql方式 M...

pexelsphoto5 將連結資料庫的方式加入model function connect() {...

利用 css 讓 ul 置中呈現

利用 css 讓 ul 置中...

以前寫網站...總是喜歡用Table 包住內容.. 而隨著時空的轉換...現在大都用div..或者....

PHP的日期時間相減方法之二

PHP的日期時間相減方法之二...

這幾天很忙...忙著寫客戶的系統.. 忙到沒時間亂開其他網站... 忙到沒時間去研究新東西... 忙...

Recommended reading

Other stories happened at this address

javascript 底下使用 htmlspecialchars

javascript 底下使...

pexelsphoto Javascript中使用一個函數達到PHP的htmlspecialchar...

還要cookies

還要cookies

U吵著Mandy說還要cookies。 當下我的腦袋裡卻閃過用session吧,cookie不安全。...

新一代小鮮肉啊~

新一代小鮮肉啊~

新一代小鮮肉啊~

Mandy下廚了~

Mandy下廚了~

Mandy下廚了~

一碗麵,簡簡單單的午餐、簡簡單單的滿足。

一碗麵,簡簡單單的午餐、簡簡...

塊錢的豆芽、塊錢的韭菜、塊錢的青江菜、塊錢的香菜、塊的細黃麵。 加上紅蔥頭肉燥、一點黑醋,攪拌一起。...

如何使用javascript判斷身分證號跟居留證格式

如何使用javascript...

首先,我是把如何用javascript判斷字串中必須包含中英文的方式延伸~ 將每一個字轉換成 ASC...

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