欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-13 12:59:45
...
数组合并问题(已更新)
本帖最后由 lazygc520 于 2014-04-08 16:17: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',
),
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
数组合并有关问题(已更新)

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • 数组合并有关问题(已更新)
  • 专题推荐