Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-05-26 08:20:46
Original
976 people have browsed it

fopen函数对于文件的读定操作是专业的并且速度是非常的快了,有时我们没用用到数据库只用到了txt文件了,下面我们来看看fopen从100万条记录的文本文件取出重复数最多的前10条的例子。

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);
Copy after login


永久链接:

转载随意!带上文章地址吧。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template