Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function array_unique()


previous

Advertisements

Syntax

array_unique ( $array );

Definition and Usage

The array_unique() function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed.

Paramters

ParameterDescription
array1Required. Specifies an array.

Example

Try out following example:

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?> 

This will produce following result:

Array
(
    [a] => green
    [0] => red
    [1] => blue
)

previous Printer Friendly

Advertisements


  

Advertisements