Jump to: navigation, search

Php array unique

From w3cyberlearnings

Contents

PHP function array_unique

This function removes duplicate values from an array.

Syntax array_unique

  • array: array input
array_unique(array);

Example 1

  • Keep 'a'=>30, remove 'c'=>30
<?php

$score= array('a'=>30,'b'=>20,'c'=>30);
$r = array_unique($score);

print_r($r);
?>

Output

Array
(
    [a] => 30
    [b] => 20
)


Example 2

<?php

$score= array('a'=>30,'b'=>20,'c'=>30,'x'=>30,'y'=>32,'bx'=>20);
$r = array_unique($score);

print_r($r);
?>

Output


Array
(
    [a] => 30
    [b] => 20
    [y] => 32
)

Related Links


Navigation
Web
SQL
MISC
References