天天看點

php數組根據某個字段去重複資料,php數組某個字段資料重複問題

1. 定義一個空數組作為容器,

$send_box_array = array(

'total'=>0, //不重複資料的總條數(總箱數)'list'=>array() //沒有重複資料的數組(箱數名稱)

);

2.在循環檢索結果資料中判斷重複資料

第一種: isset判斷foreach ($result as $good_list) {

// get the total send box num

if(!isset($send_box_array ['list'][$good_list['send_box_no']])){

$send_box_array ['total']++;

$send_box_array ['list'][$good_list['send_box_no']] = '';

}

。。。

}

self::$wms_data[$num]['user_def2'] = $send_box_array['total'];

第二種: in_array()

foreach ($result as $good_list) {

// get the total send box num

if(!in_array($good_list['send_box_no'],

$send_box_array ['list'])){$send_box_array ['total']++;

$send_box_array ['list'][] = $good_list['send_box_no'];

}

。。。

}

self::$wms_data[$num]['user_def2'] = $send_box_array['total'];

以上就介紹了php數組某個字段資料重複問題,包括了重複資料方面的内容,希望對PHP教程有興趣的朋友有所幫助。

本文原創釋出php中文網,轉載請注明出處,感謝您的尊重!