I have a top 10 list right here. The list contains all the IPs who visited the domain (out of my log files) and my code below gives me the top 10 IPs of them.
But I want it more dynamically. Like if there are more then 10 different IPs, give me just the 10 IPs that appear the most. If the amount of different IPs is less then 10, just give me all the IPs there are.
The code for this:
$all_ips = array_count_values($ip_array);
arsort($all_ips);
$count = count($all_ips);
$keys = array_keys($all_ips);
$topTenIp = array();
$count = $count -1;
for($i=0; $i <= $count; $i++){
if($count < 9){
$topTenIp[] = $keys[$i];
}else{
$topTenIp[] = $keys[$i];
}
}
This works okay but not perfect. If the amount of IPs is below 10, it gives me all the IPs there are. But if there are more then 10, it doesn't give me the 10 most appearing IPs, it just gives me all IPs of the log script.
I hope you understood what I was trying to say. I'm from Germany, so my English isn't that good.
Thanks anyway :)