eon201 Posted November 16, 2007 Share Posted November 16, 2007 Hi, Im attempting something which I have NO idea how to do... I have an array like so... <?php // Now calculate top 5 pages this day foreach ($url_total_today as $key2 => $value2){ echo "$value2<br/>"; } ?> It spits out a ridiculous amount of urls. Probably around 500. What I would like it to do is to count how many times each url appears and display it plainly like so... 142 - url1.php 67 - url2.html 56 - url3.htm 23 - url4.php 5 - url5.php Can anybody help me with this? Ive tried using the 'array_unique' funtion in conjunction with the 'count' function but no joy. ??? Thanks In advance. Eon201 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 16, 2007 Share Posted November 16, 2007 You probably want to look at the array_count_values()[/function] Ken Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 16, 2007 Author Share Posted November 16, 2007 hmm. Ok half way there now. Thanks How would I only display the top five?? Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 16, 2007 Author Share Posted November 16, 2007 Ok I have achieved it with the asort function. Problem is I need to work out how to get it to display only the first five iterations of the loop. Does anyone know how to stop a loop at a certain point?? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 To stop a loop, you can use break; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 16, 2007 Share Posted November 16, 2007 If you only want the top five, just do 5 iterations of the loop: <?php $test_ary = range(99,1); for ($i=0;$i<5;$i++) echo $test_ary[$i] . "<br>\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 20, 2007 Author Share Posted November 20, 2007 Thanks everybody! Solved now. Quote Link to comment 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.