2levelsabove Posted October 31, 2008 Share Posted October 31, 2008 hello, I have an array that contains the following data. 10/31/08*10/31/08*10/31/08*10/31/08*10/31/08*10/31/08*10/30/08/*10/30/08 for graphing purposes i need to get information like 10/31/08 = 6 visits 10/30/08 = 2 visits what would be the best way ? I am trying to build my own traffic graph thanks Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/ Share on other sites More sharing options...
JonnoTheDev Posted October 31, 2008 Share Posted October 31, 2008 Is this data coming from a mysql query as you could obtain the desired result using COUNT and GROUP BY clauses in the query. Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679362 Share on other sites More sharing options...
rhodesa Posted October 31, 2008 Share Posted October 31, 2008 <?php $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08'); $data = array(); foreach($array as $item){ if(is_array($data[$item])) $data[$item]++; else $data[$item] = 1; } print_r($data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679365 Share on other sites More sharing options...
2levelsabove Posted October 31, 2008 Author Share Posted October 31, 2008 rhodesa, thanks for your repky. I ran your code and i got : Array ( [10/31/08] => 1 [10/30/08] => 1 ) what I want to get is: Array ( [10/31/08] => 6 [10/30/08] => 2 ) so that I can graph the result Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679381 Share on other sites More sharing options...
rhodesa Posted October 31, 2008 Share Posted October 31, 2008 my bad... <?php $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08'); $data = array(); foreach($array as $item){ if(isset($data[$item])) $data[$item]++; else $data[$item] = 1; } print_r($data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679382 Share on other sites More sharing options...
2levelsabove Posted October 31, 2008 Author Share Posted October 31, 2008 thanks a lot man! Mind just doesnt work this early . Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679386 Share on other sites More sharing options...
kenrbnsn Posted October 31, 2008 Share Posted October 31, 2008 Have you looked at the function array_count_values()? <?php $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08'); $data = array_count_values($array); echo '<pre>' . print_r($data,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679389 Share on other sites More sharing options...
2levelsabove Posted October 31, 2008 Author Share Posted October 31, 2008 amazing stuff !!! thanks a lot both of you. Now i really feel like a retard. Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679392 Share on other sites More sharing options...
rhodesa Posted October 31, 2008 Share Posted October 31, 2008 Have you looked at the function array_count_values()? <?php $array = array('10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/31/08','10/30/08','10/30/08'); $data = array_count_values($array); echo '<pre>' . print_r($data,true) . '</pre>'; ?> Ken always taking shortcuts.... Quote Link to comment https://forums.phpfreaks.com/topic/130884-solved-php-array-help/#findComment-679397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.