Loop through and match duplicates

Define $emailArr outside your loop. Then append each item to it.

$emailArr = array(); // define here
foreach ($orders as $key => $value) { 
    $email = $value->getEmail();
    if(in_array($email, $emailArr)) {
          // skip or do something else
        echo "Matched";
    else {
        array_push($emailArr, $email);
        // do other stuff
        echo "added new";

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top