phpstudy|php fopen从100万条记录的文本文件取出重复数最多的前10条

更新时间:2019-10-14    来源:文本特效    手机版     字体:

【www.bbyears.com--文本特效】

100万条记录的文本文件,取出重复数最多的前10条。

 

示例文本:

 

098
123
234
789
……
234
678
654
123

$fp = fopen('文件', 'r');

while($buf = fgets($fp)) {   $res[$buf]++;

}

fclose($fp);

arsort($res);

$res = array_keys(array_slice($res, 0, 10));

print_r($res);
$a = file('文件');

$res = array_count_values($a);

arsort($res);

$res = array_keys(array_slice($res, 0, 10));

print_r($res);

本文来源:http://www.bbyears.com/wangyetexiao/73234.html

热门标签

更多>>

本类排行