Add two arrays and write an array to the known arrays a and B of another array:
// Array a: array (0 => array ('cust _ no' => '310f6 1VA5A ', 'lotno' => '2x15 ', 'part _ count' => '0',), 1 => array ('cust _ no' => '310f6 1VA5A ', 'lotno' => '2z25 ', 'part _ count' => '5',), // array B: array (0 => array ('cust _ no' => '310f6 1VA5A ', 'lotno' => '2z15', 'part _ count' => '000000',), 1 => array ('cust _ no' => '310f6 1VA5A ', 'lotno' => '123', 'part _ count' => '28 ',),)
Add the result of array B to array a, and accumulate the part_count corresponding to cust_no and lotno. The result is as follows:
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', ),)
How can this be done? What array functions are required? Thank you!
Reply to discussion (solution)
$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?
Combine the values of cust_no and lotno into a key to judge the repeated
Combine the values of cust_no and lotno into a key to judge the repeated
Oh, you can use it like this. Thank you!