Remove duplicate elements from array in PHP


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.