Array merge issues (updated)
This post was last edited by lazygc520 on 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 ',
),
)
Conditions: When both Arr_time and C_TYPE,SNP are identical, combine the same array into a new two-dimensional array and set the date form yyyy-mm-dd_$i to its ordinal number. Become for example
Array (
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 ',
),
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 ',
),
)
How can i solve it?
------Solution--------------------
$res = Array ();
foreach ($ar as $t) {
$k = Join (' _ ', Array ($t [' arr_time '), $t [' C_type '], $t [' SNP ']);
$res [$k] = $t;
}
Print_r ($res);
Have
Array
(
[30/03/2014 9:00_d22_15] = = Array
(
[0] = = Array