Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:31:41+00:00 2026-06-01T21:31:41+00:00

I am currently using php to help me find the valide and non-duplicated entry,

  • 0

I am currently using php to help me find the valide and non-duplicated entry,

which i need

  1. a list of valid and non-duplicated
  2. entry a list of invalid input (unique)
  3. a list of duplicate input

My approach is first create 5 array 2 for orginal ,1 for no mistake (empty),
1 for valid (empty) , 1 for duplicate (empty)

First using one of orginal array, for each one element : check valid
and check duplicate, if invalid , put into invalid array , and check duplicate by using inarray

after all, i get one array of invalid and duplicate , then using the orginal array, check which element is not in that two array. And job done.

My problem is, it seems quite inefficiency, how can i improve it? (Perferable if using some famous algorithm)

Thank you.

   // get all duplicate input and store in an array
    for ($row = 1; $row <= $highestRow; $row++) {
    for ($y = 0; $y < $highestColumn; $y++) {
        $val = $sheet->getCellByColumnAndRow($y, $row)->getValue();

//use reg exp to check whether it is valid
        if ($y == $mailColumn && !preg_match($pattern,$val))
        {$invaild[]=$row;}
//if valid, test whether it is duplicate
        elseif ($y == $mailColumn && in_array($val,$email))
        {$duplicate[]=$val;
        $duplicate[]=$row;}

        if ($y == $mailColumn)
        {$email[]=$val;
        $email=array_unique($email);}

      }
    }


// unique invalid array since i just need  invalid  inputs, not the invalid + duplicate input 
$invaild=array_unique($invaild);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:31:42+00:00Added an answer on June 1, 2026 at 9:31 pm

    try this:

    <?php     
    echo "<pre>";    
    
    $array1 = array("a@b.com","c","c","d@e.com","test1","","test3","test2","test3");    
    
    $array_no_mistake = array_filter($array1,function($subject){if(trim($subject)=="") return true;});    
    
    $array_uniq = array_diff(array_unique($array1),$array_no_mistake);    
    
    $array_dups = array_diff_assoc(array_diff($array1,$array_no_mistake),$array_uniq);    
    
    $array_valid = array_filter($array_uniq,function($subject){    
        if (preg_match('/\A(?:[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z/i', $subject)) {    
        return true;    
    } else {    
        return false;    
    }    
    });    
    
    
    $array_invalid = array_diff_assoc($array_uniq,$array_valid);    
    
    
    print_r($array1);    
    
    print_r($array_no_mistake);    
    
    print_r($array_uniq);    
    
    print_r($array_dups);    
    
    print_r($array_valid);    
    
    print_r($array_invalid);    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I'm currently developing a website which stores bookmarks in a MySQL database using PHP
I'm currently using PHP, JAVASCRIPT, MYSQL, XHTML, CSS to develop my site. Note that
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I am currently using jQuery to load a variable php layout depending on the
I am currently using various back-end services and I want to use PHP to
I'm reading some XML with PHP and currently using the DOMDocument class to do
How can I setup expires headers in PHP + Apache? I'm currently using an
I'm using the JQuery AJAX function to deliver data to a PHP doc. Currently,
I am currently doing a project, in which I need to stop the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.