Rumah > pembangunan bahagian belakang > tutorial php > 数组合并有关问题(已更新)

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

WBOY
Lepaskan: 2016-06-13 11:54:08
asal
764 orang telah melayarinya

数组合并问题(已更新)

本帖最后由 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 />)
Salin selepas log masuk



条件:当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 />)
Salin selepas log masuk

请问怎么求解?
------解决方案--------------------
$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 />
Salin selepas log masuk
Array<br>(<br>    [30/03/2014  9:00_D22_15] => Array<br>        (<br>            [0] => Array<div class="clear">
                 
              
              
        
            </div>
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan