您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

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

2024/5/6 17:01:59发布5次查看
数组合并问题(已更新)
本帖最后由 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

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录