Add two arrays and write one array to another.

Source: Internet
Author: User
Tags what array
Add two arrays, and write an array to another known array a and array B: array a: array & nbsp; (& nbsp; 0 & nbsp; & gt; & nbsp; array & nbsp; (& nbsp; cust_no & nbsp; & gt; & nbsp; 310F6 & nbsp; 1VA5A, and add two arrays to write one array to another
Known arrays a and B:

// Array:
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' => '123 ',
),
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!

Share :??? Array? (???? 'Cust _ no '? =>? '310f6? 1VA5A ',???? 'Lotno '? =>? '2... 'data-pics = ''>


------ Solution --------------------
$t=array();
foreach(array_merge($a,$b) as $v){
if(!isset($t[$v['cust_no'].'_'.$v['lotno']])){

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.