Finding the repeating part of data

Source: Internet
Author: User
    1. 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:

    1. 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)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.