已知数组a和数组b:
//数组a:array ( 0 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '2X15', 'part_count' => '0', ), 1 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '2Z25', 'part_count' => '5', ),)//数组b:array ( 0 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '2Z15', 'part_count' => '100', ), 1 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '3115', 'part_count' => '28', ),)
array ( 0 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '2X15', 'part_count' => '0', ), 1 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '2Z15', 'part_count' => '105', ), 2 => array ( 'cust_no' => '310F6 1VA5A', 'lotno' => '3115', 'part_count' => '28', ),)
$t=array();foreach(array_merge($a,$b) as $v){ if(!isset($t[$v['cust_no'].'_'.$v['lotno']])){ $t[$v['cust_no'].'_'.$v['lotno']]=$v; }else{ $t[$v['cust_no'].'_'.$v['lotno']]['part_count']+=$v['part_count']; } } print_r(array_values($t));
$v['cust_no'].'_'.$v['lotno']这句是什么意思?
将 cust_no 和 lotno的值组成键判断重复用的
将 cust_no 和 lotno的值组成键判断重复用的
哦,原来可以这样用啊。谢谢了!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号