I have an array like:
$arr[0] = ("1-3-2011","1","15"); //date(dd-mm-yyyy),id,amt
$arr[1] = ("1-4-2011","2","5");
$arr[2] = ("12-3-2011","6","20");
$arr[3] = ("1-3-2011","10","10");
$arr[4] = ("12-3-2011","3","10");
$arr[5] = ("1-4-2011","5","15");
$arr[6] = ("1-3-2011","7","15");
From this I need to generate a condensed array like
$newarr[0] = ("1-3-2011","1,7,10","40");
$newarr[0] = ("1-4-2011","2,5","20");
..
...
Basically the first one is a multidimentional array, containing date,id, and amount. In the new array, I need to condense the previous one for each unique date, ids as a csv string for duplicate dates, and amounts added.
What’s the most efficient way to do this, performance wise?
Something like this should do it:
Working example: