-6

Imagine that you have this PHP code:$array1 = array("henk", "jackson", "henk");. Is there a way to check if $array1 has two of the same values in it (in this case henk) and then make it delete one of them so one stays in the array?

  • 1
    [This](http://php.net/manual/en/function.array-unique.php) should help you – Danielius Jul 17 '17 at 14:19
  • Good luck, and for next time read how to ask and search before asking, because [this](https://stackoverflow.com/questions/307650/how-to-remove-duplicate-values-from-an-array-in-php) is exactly the same question as yours. – Danielius Jul 17 '17 at 14:22
  • 1
    If an answer solved your problem, consider accepting the answer. Here's how http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. You'll earn points and others will be encouraged to help you. *Welcome to Stack!* – Jay Blanchard Jul 17 '17 at 14:22
  • 1
    You have a history of off-topic or heavily downvoted questions and are at risk of losing your question-asking privileges. You should [read this before you post your next one](http://meta.stackoverflow.com/questions/254262/before-you-post-your-next-question). – Jay Blanchard Jul 17 '17 at 14:23

1 Answers1

1

All you need is array_unique():

$array1 = array("henk", "jackson", "henk");
$array2 = array_unique($array1);
print_r($array2);

Result:

Array
(
    [0] => henk
    [1] => jackson
)
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119