Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created November 4, 2012 20:15
Show Gist options
  • Select an option

  • Save apphp-snippets/4013482 to your computer and use it in GitHub Desktop.

Select an option

Save apphp-snippets/4013482 to your computer and use it in GitHub Desktop.
This code allows to remove all duplicate elements from an array using PHP array_unique() function.
<?php
/* Source: http://www.apphp.com/index.php?snippet=php-remove-duplicates-in-array */
$input = array("a"=>"apple", "pear", "b"=>"apple", "orange", "avocado", "banana");
print_r($input);
$result = array_unique($input);
print_r($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment