Array merging problems (Updated)

Source: Internet
Author: User
Array merging problem (Updated) This post was last edited by lazygc520 from 2014-04-0816: 17: 15 array & nbsp; (& nbsp; 0 & nbsp; & gt; & nbsp; array & nbsp; (& nbsp; cust_no & array merging (Updated)

This post was last edited by lazygc520 at 16:17:15 on

array (
0 =>
array (
'cust_no' => '237109S92B',
'hi_no' => 'MEC38-431',
'arr_time' => '30/03/2014 9:00',
'totals' => 15,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 1,
'c_type' => 'D22',
),
1 =>
array (
'cust_no' => '237109S92B',
'hi_no' => 'MEC38-431',
'arr_time' => '30/03/2014 9:00',
'totals' => 15,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 1,
'c_type' => 'D22',
),
2 =>
array (
'cust_no' => '237033AW0A',
'hi_no' => 'BEM330-500',
'arr_time' => '30/03/2014 19:00',
'totals' => 15,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 1,
'c_type' => 'X11M',
),
3 =>
array (
'cust_no' => '237033AW0A',
'hi_no' => 'BEM330-500',
'arr_time' => '30/03/2014 19:00',
'totals' => 45,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 3,
'c_type' => 'X11M',
),
4 =>
array (
'cust_no' => '237033AW0A',
'hi_no' => 'BEM330-500',
'arr_time' => '30/03/2014 19:00',
'totals' => 45,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 3,
'c_type' => 'X11M',
),
5 =>
array (
'cust_no' => '237033AW0A',
'hi_no' => 'BEM330-500',
'arr_time' => '1/04/2014 19:00',
'totals' => 45,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 3,
'c_type' => 'X11M',
),
)



Condition: When both arr_time and c_type and snp are the same, the array with the same conditions is merged into a new two-dimensional array, and the date format yyyy-mm-dd _ $ I is set as its serial number. For example
array (
0 =>
array (
'no'=> '2014-04-08_1',
'cust_no' => '237109S92B',
'hi_no' => 'MEC38-431',
'arr_time' => '30/03/2014 9:00',
'totals' => 15,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 1,
'c_type' => 'D22',
),
1 =>
array (
'no'=> '2014-04-08_1',
'cust_no' => '237109S92B',
'hi_no' => 'MEC38-431',
'arr_time' => '30/03/2014 9:00',
'totals' => 15,
'ch_date' => '26/03/2014 0:00',
'snp' => 15,
'mount' => 1,
'c_type' => 'D22',
),
)

How can I solve this problem?
------ Solution --------------------
$res = array();
foreach($ar as $t) {
$k = join('_', array($t['arr_time'], $t['c_type'], $t['snp']));
$res[$k][] = $t;
}
print_r($res);
Get
Array
(
[30/03/2014 9:00_D22_15] => Array
(
[0] => Array

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.