PHP-Array_unique method

Array_unique is a method in PHP which is used to display unique elements in an Array. It removes duplicate elements. The method takes the array as an Input and returns an array that contains only unique values.


 Keep in mind that the array will not re- position the elements after it removes duplicates. 

For example-

$arr=$array (1,2,2,3);

In this array, $arr [0]=1 ,  $arr[1]=2,  $arr[2]=2, $arr[3]=3

Then, if we apply the method to this array.

$arr=Array_unique ($arr);

We get an array which has elements-

 $arr[0]=1,  $arr[1]=2 and $arr [3]=3;
There will be a null element at index 2, since that element was removed. So the element which was at index 3, will still remain at 3 and it would not re position itself to index 2.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s