Posted By

apphp-snippets on 02/25/13


php remove duplicate

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Remove duplicate elements from array in PHP

 / Published in: PHP


This code allows to remove all duplicate elements from an array using PHP array_unique() function.

  1. <?php
  2. $input = array("a"=>"apple", "pear", "b"=>"apple", "orange", "avocado", "banana");
  3. print_r($input);
  4. $result = array_unique($input);
  5. print_r($result);
  6. ?>

Report this snippet  

You need to login to post a comment.