GaRd3NiA Posted December 18, 2009 Share Posted December 18, 2009 Hi, i have an array as below : Array ( [0] => Array ( [time] => 2009-12-08 [count] => 1 ) [1] => Array ( [time] => 2009-12-03 [count] => 2 ) [2] => Array ( [time] => 2009-12-03 [count] => 9 ) [3] => Array ( [time] => 2009-12-03 [count] => 1 ) [4] => Array ( [time] => 2009-12-02 [count] => 10 ) [5] => Array ( [time] => 2009-12-02 [count] => 10 ) [6] => Array ( [time] => 2009-11-30 [count] => 10 ) [7] => Array ( [time] => 2009-11-27 [count] => 10 ) ) Any idea on how to find the total count in each day? Thanks in advance!!! Jason Link to comment https://forums.phpfreaks.com/topic/185572-do-a-count-of-a-multidimensional-array/ Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 $count=0; foreach ($array as $key=>$value) { $count+=$array[$key]['count']; } Link to comment https://forums.phpfreaks.com/topic/185572-do-a-count-of-a-multidimensional-array/#findComment-979711 Share on other sites More sharing options...
GaRd3NiA Posted December 18, 2009 Author Share Posted December 18, 2009 Thanks for your kind reply teynon. Sorry not to mention in the first post, actually i would like to have the output as below: Array ( [0] => Array ( [time] => 2009-12-08 [count] => 1 ) [1] => Array ( [time] => 2009-12-03 [count] => 12 <-- the sum of count in 2009-12-03 ) [2] => Array ( [time] => 2009-12-02 [count] => 20 <-- the sum of count in 2009-12-02 ) [3] => Array ( [time] => 2009-11-30 [count] => 10 ) [4] => Array ( [time] => 2009-11-27 [count] => 10 ) ) Thanks!!! Link to comment https://forums.phpfreaks.com/topic/185572-do-a-count-of-a-multidimensional-array/#findComment-979715 Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 $newArray=array(); foreach ($array as $key=>$value) { $newArray[$array[$key]['time']]+=$array[$key]['count']; } Its similar to yours only, the keys are the dates instead of 0,1,2,3 Link to comment https://forums.phpfreaks.com/topic/185572-do-a-count-of-a-multidimensional-array/#findComment-979718 Share on other sites More sharing options...
GaRd3NiA Posted December 18, 2009 Author Share Posted December 18, 2009 You r the man, that helps. Thanks a lot teynon.... cheers!!!! -- Jason Link to comment https://forums.phpfreaks.com/topic/185572-do-a-count-of-a-multidimensional-array/#findComment-979721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.