-
Now there is a batch of Address book data (more than 10,000 people in the newsletter) need to find out the duplicate of every two people's Address book (that is, who and whose address book is repeated how many) to everyone's address book is 22.
For example there are abcde four people in the Address book to find the AB AC AD AE BC BD be CD CE de contacts between the number of duplicate bars
Mobile phone number Repeat, I think these two address books repeat
This is a data sheet, with more than 10,000 contacts.
The JSON of the list character Gencun is the contents of the Address Book
One person Address Book 100 to 1000 Lines
What I'm trying to do now is to take out everyone's address book and then compare the first person to the rest of us (the array of foreach, which is nested in foreach), and then take the second person's comparison with the rest of us, and so on.
Script section Code
then run the script script for more than 20 hours to run half of the memory, CPU consumption is also relatively high script efficiency is too low
Ask, there is no better way to find out the repetition of this batch of data, or how the script optimization optimization
Thank you
Reply content:
-
Now there is a batch of Address book data (more than 10,000 people in the newsletter) need to find out the duplicate of every two people's Address book (that is, who and whose address book is repeated how many) to everyone's address book is 22.
For example there are abcde four people in the Address book to find the AB AC AD AE BC BD be CD CE de contacts between the number of duplicate bars
Mobile phone number Repeat, I think these two address books repeat
This is a data sheet, with more than 10,000 contacts.
The JSON of the list character Gencun is the contents of the Address Book
One person Address Book 100 to 1000 Lines
What I'm trying to do now is to take out everyone's address book and then compare the first person to the rest of us (the array of foreach, which is nested in foreach), and then take the second person's comparison with the rest of us, and so on.
Script section Code
then run the script script for more than 20 hours to run half of the memory, CPU consumption is also relatively high script efficiency is too low
Ask, there is no better way to find out the repetition of this batch of data, or how the script optimization optimization
Thank you
$data = array( array('id'=>1,'name'=>1), array('id'=>2,'name'=>2), array('id'=>3,'name'=>3), array('id'=>1,'name'=>2));$ret = array();# 数据遍历一次,以计算重复key作为key新建数据,如果存在value +1,如果不存在设置为1foreach($data as $k=>$v){ $_id = $v['id']; $_name = $v['name']; if (array_key_exists($_id, $ret)) { $ret[$_id]++; }else{ $ret[$_id] = 1; }}# 遍历结果foreach($ret as $k=>$v){ echo "{$k}出现{$v}次\n";}#print_r($id)