string - PHP how to display the 5 most reccurent words in a list -


i have list in visited websites stored (a thousand), , need display top 5 visited websites :

$websites= "site#1.com site#2.com site#1.com site#1.com site#3.com ... " 

this deliberately verbose understand what's going on:

<?php  $websites = "site#1.com site#2.com site#1.com site#1.com site#3.com";  //presuming they'll seperated single space... $sites = explode(' ', $websites);  $sitecount = array();  foreach ($sites $site) {   if (!isset($sitecount[$site])) {     $sitecount[$site] = 1;   } else {     $sitecount[$site]++;   } }  arsort($sitecount);  $finalarray = array_slice($sitecount, 0, 5);  var_dump($sitecount); 

which outputs:

array(3) {   ["site#1.com"]=&gt;   int(3)   ["site#3.com"]=&gt;   int(1)   ["site#2.com"]=&gt;   int(1) } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -