Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2013 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7601954 to your computer and use it in GitHub Desktop.
Save anonymous/7601954 to your computer and use it in GitHub Desktop.
<?php
function myfilter($src, $limit = 5){
$ref = array();
//先建立一个数组$ref,维护起一个ip到项的映射,以及ip出现的次数
foreach($src as $key => $item){
if (isset($ref[$item['ip']])){
$ref[$item['ip']][] = $key;
}else{
$ref[$item['ip']] = array($key);
}
}
//现在遍历所有的ip,并将出现次数达到$limit的项插入到用于返回的$ret数组中
$ret = array();
foreach($ref as $ip => $list){
if (count($list) >= $limit){
foreach($list as $key){
$ret[] = $src[$key];
}
}
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment