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

WBOY
發布: 2016-06-13 11:54:08
原創
739 人瀏覽過

数组合并问题(已更新)

本帖最后由 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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!