Created
November 22, 2013 15:28
-
-
Save anonymous/7601723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function myfilter($src, $limit = 5){ | |
$ref = array(); | |
//先建立一个数组$ref,维护起一个ip到项的映射,以及ip出现的次数 | |
foreach($src as $key => $item){ | |
if (isset($ref[$item['ip']])){ | |
$ref[$item['ip']]['count'] += 1; | |
$ref[$item['ip']]['keys'][] = $key; | |
}else{ | |
$ref[$item['ip']] = array('count' => 1, 'keys' => array($key)); | |
} | |
} | |
//现在遍历所有的ip,并将出现次数达到$limit的项插入到用于返回的$ret数组中 | |
$ret = array(); | |
foreach($ref as $list){ | |
if ($list['count'] >= $limit){ | |
foreach($list['keys'] 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