Posted By

apphp-snippets on 02/25/13


Tagged

php remove duplicate


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

3polars


Remove duplicate elements from array in PHP


 / Published in: PHP
 

URL: http://www.apphp.com/index.php?snippet=php-remove-duplicates-in-array

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.