首页 / PHP / 数组合并问题(已更新)
数组合并问题(已更新)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了数组合并问题(已更新),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4397字,纯文字阅读大概需要7分钟。
内容图文
![数组合并问题(已更新)](/upload/InfoBanner/zyjiaocheng/199/5a1ec3493117462a8d3bd4efd11bd8f4.jpg)
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 ) ))接下来该怎么做,你应该会的
内容总结
以上是互联网集市为您收集整理的数组合并问题(已更新)全部内容,希望文章能够帮你解决数组合并问题(已更新)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。