数组合并问题(已更新)

WBOY
发布: 2016-06-23 13:59:21
原创
789 人浏览过

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',  ),)
登录后复制



条件:当arr_time和c_type,snp都相同时,把条件相同的数组合并为新的二维数组,并设定日期形式yyyy-mm-dd_$i为其序号。变成例如
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',  ),)
登录后复制

请问怎么求解?


回复讨论(解决方案)

$res = array();foreach($ar as $t) {  $k = join('_', array($t['arr_time'], $t['c_type'], $t['snp']));  $res[$k][] = $t;}print_r($res);
登录后复制
Array(    [30/03/2014  9:00_D22_15] => 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                )        )    [30/03/2014 19:00_X11M_15] => Array        (            [0] => 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                )            [1] => 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                )            [2] => 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                )        )    [1/04/2014 19:00_X11M_15] => Array        (            [0] => 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                )        ))
登录后复制
接下来该怎么做,你应该会的

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!