How to use array unique in PHP

In this article, I will explain how the array_unique() function can be used in PHP.
  • 1611

array_unique() function in PHP

  • The array_unique() function removes duplicate values from an array.

  • the first value will be kept and the other will be removed, If two or more array values are the same, .

Syntax

array_unique(array)

Parameter

  • array  array is required parameter. Specifies an array.

Example

The following example show to how the array_unique() function can be used in PHP.

<html>

<body>

<h3 style="color: saddlebrown;">array_unique() function example in PHP</h3>  

    <?php

    $a = array("a" => "Nitin", "Ravi", "b" => "Nitin", "Rajesh", "Richa");

    $result = array_unique($a);

    print_r($result);

    ?>

</body>

</html>

 

Output

unique.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.