php数组某个字段数据重复问题
程序员文章站
2022-06-09 11:10:40
...
1. 定义一个空数组作为容器,
$send_box_array = array(
// 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']] = '';
}
。。。
}
$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教程有兴趣的朋友有所帮助。