Heim >Backend-Entwicklung >PHP-Tutorial >数组合并有关问题(已更新)

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

WBOY
WBOYOriginal
2016-06-13 11:54:08753Durchsuche

数组合并问题(已更新)

本帖最后由 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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn