Home  >  Article  >  Backend Development  >  php mysql millions of data to remove duplicate data_PHP tutorial

php mysql millions of data to remove duplicate data_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:291025browse


//Define an array to store the results after deduplication
$result = array();
//Read uid list file
$fp = fopen('test.txt', 'r');

while(!feof($fp))
{
$uid = fgets($fp);
$uid = trim($uid);
$uid = trim($uid, "r");
$uid = trim($uid, "n");

if($uid == '')
{
continue;
}
//Us uid as key to see if the value exists
if(empty($result[$uid]))
{
$result[$uid] = 1;
}
}

fclose($fp);

//Save results to file
$content = '';
foreach($result as $k => $v)
{
$content .= $k."n";
}
$fp = fopen('result.txt', 'w');
fwrite($fp, $content);
fclose($fp);
?> 


//Define an array to store the results after deduplication
$result = array();
//Read the first uid list file and put it into $result_1
$fp = fopen('test_1.txt', 'r');
while(!feof($fp))
{
$uid = fgets($fp);
$uid = trim($uid);
$uid = trim($uid, "r");
$uid = trim($uid, "n");
if($uid == '')
{
continue;
}
//Write $result with uid as key, if there are duplicates, they will be overwritten
$result[$uid] = 1;
}
fclose($fp);
//Read the second uid list file and perform duplication operation
$fp = fopen('test_2.txt', 'r');
while(!feof($fp))
{
$uid = fgets($fp);
$uid = trim($uid);
$uid = trim($uid, "r");
$uid = trim($uid, "n");
if($uid == '')
{
continue;
}
//Us uid as key to see if the value exists
if(empty($result[$uid]))
{
$result[$uid] = 1;
}
}
fclose($fp);
//The result saved in $result is the result after deduplication, which can be output to a file and the code is omitted
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630861.htmlTechArticle?php tutorial//Define an array to store the results after deduplication $result = array(); //Read uid list file $fp = fopen('test.txt', 'r'); while(!feof($fp)) { $uid = fgets($fp); $ui...
Statement:
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