首页 > 后端开发 > php教程 > 数组合并有关问题(已更新)

数组合并有关问题(已更新)

WBOY
发布: 2016-06-13 11:54:08
原创
757 人浏览过

数组合并问题(已更新)

本帖最后由 lazygc520 于 2014-04-08 16:17:15 编辑
array (<br />  0 => <br />  array (<br />    'cust_no' => '237109S92B',<br />    'hi_no' => 'MEC38-431',<br />    'arr_time' => '30/03/2014  9:00',<br />    'totals' => 15,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 1,<br />    'c_type' => 'D22',<br />  ),<br />  1 => <br />  array (<br />    'cust_no' => '237109S92B',<br />    'hi_no' => 'MEC38-431',<br />    'arr_time' => '30/03/2014  9:00',<br />    'totals' => 15,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 1,<br />    'c_type' => 'D22',<br />  ),<br />  2 => <br />  array (<br />    'cust_no' => '237033AW0A',<br />    'hi_no' => 'BEM330-500',<br />    'arr_time' => '30/03/2014 19:00',<br />    'totals' => 15,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 1,<br />    'c_type' => 'X11M',<br />  ),<br />  3 => <br />  array (<br />    'cust_no' => '237033AW0A',<br />    'hi_no' => 'BEM330-500',<br />    'arr_time' => '30/03/2014 19:00',<br />    'totals' => 45,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 3,<br />    'c_type' => 'X11M',<br />  ),<br />  4 => <br />  array (<br />    'cust_no' => '237033AW0A',<br />    'hi_no' => 'BEM330-500',<br />    'arr_time' => '30/03/2014 19:00',<br />    'totals' => 45,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 3,<br />    'c_type' => 'X11M',<br />  ),<br /> 5 => <br />  array (<br />    'cust_no' => '237033AW0A',<br />    'hi_no' => 'BEM330-500',<br />    'arr_time' => '1/04/2014 19:00',<br />    'totals' => 45,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 3,<br />    'c_type' => 'X11M',<br />  ),<br />)
登录后复制



条件:当arr_time和c_type,snp都相同时,把条件相同的数组合并为新的二维数组,并设定日期形式yyyy-mm-dd_$i为其序号。变成例如
array (<br />  0 => <br />  array (<br />    'no'=> '2014-04-08_1',<br />    'cust_no' => '237109S92B',<br />    'hi_no' => 'MEC38-431',<br />    'arr_time' => '30/03/2014  9:00',<br />    'totals' => 15,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 1,<br />    'c_type' => 'D22',<br />  ),<br />  1 => <br />  array (<br />    'no'=> '2014-04-08_1',<br />    'cust_no' => '237109S92B',<br />    'hi_no' => 'MEC38-431',<br />    'arr_time' => '30/03/2014  9:00',<br />    'totals' => 15,<br />    'ch_date' => '26/03/2014  0:00',<br />    'snp' => 15,<br />    'mount' => 1,<br />    'c_type' => 'D22',<br />  ),<br />)
登录后复制

请问怎么求解?
------解决方案--------------------
$res = array();<br />foreach($ar as $t) {<br />  $k = join('_', array($t['arr_time'], $t['c_type'], $t['snp']));<br />  $res[$k][] = $t;<br />}<br />print_r($res);<br />
登录后复制
Array<br>(<br>    [30/03/2014  9:00_D22_15] => Array<br>        (<br>            [0] => Array<div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板