Created
August 27, 2012 13:19
-
-
Save tim-peterson/3488345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$out = array(); | |
$myArray=array( | |
array( | |
'date' => '2011-05-13', | |
'value' => 2 | |
), | |
array( | |
'date' => '2011-05-14', | |
'value' => 5 | |
), | |
array( | |
'date' => '2011-05-13', | |
'value' => 7 | |
), | |
array( | |
'date' => '2011-05-14', | |
'value' => 3 | |
), | |
); | |
// Looping over each input array item | |
foreach ($myArray as $elem) { | |
$out[] = $elem['date']; | |
$out[$elem['date']]['value'] += $elem['value']; | |
} | |
print_r($out); | |
//Array ( [0] => 2011-05-13 [1] => Array ( [value] => 9 ) [2] => 2011-05-14 [3] => Array ( [value] => 8 ) [4] => 2011-05-13 [5] => 2011-05-14 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment