Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have the following piece of code...

public function setEmailAddresses() {
    $this->matches = array();
    $this->matchRegex = '/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/'; 
    preg_match_all($this->matchRegex, $this->getSearchResults(), $this->matches);
    $this->emailAddresses = array_values($this->matches[0]);
}

Now I want to take the e-mail addresses in the array, and remove any array entries that are redundant. Restated, if the same email address is found in the array three times, I want to reduce it down to only being present once. Can someone help me accomplish this?

Also, is that the best regex to use for identifying an email address? It is working for me, but I want to know if there is a better one I should use?

Thanks in advance for your help!

share|improve this question

closed as off topic by Paul, Michael K Jun 22 '12 at 22:08

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 3 down vote accepted

http://php.net/manual/en/function.array-unique.php

share|improve this answer
Not sure why this was down-voted. It's straight to the point. – Levinaris Oct 21 '11 at 13:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.