Showing posts with label PHP Remove Duplicate values from Array. Show all posts
Showing posts with label PHP Remove Duplicate values from Array. Show all posts

Thursday, 25 September 2014

array_unique in PHP

 array_unique() Function is utilized to remove duplicate values from an input array.
If two or more values from array are the same, the first appearance will be kept and the other will be removed.

Syntax:

array_unique(array)
array : Required. Specifying an array
Tip : The returned array will keep the first array item's key type.

Example:

<?php
$daysarr1 = array( "a"=>"Sunday","b"=>"Monday","c"=>"Sunday" );
print_r(array_unique($daysarr1));
?>

O/P:

Array ( 
       [a] = > Sunday 
       [b] => Monday 
       )