Remove duplicate values from an array in PHP

balandžio 23rd, 2012

Today’s chalenge: How to remove the duplicate values from a PHP array?

after short search i found solution array_unique.

How this function works:

<?php

$input = array(1, 2, 2, 3, 3, 4);

$result = array_unique($input);

var_dump($result); ?>

will output:
array(4) {
[0]=> int(1)
[1]=> int(2)
[3]=> int(3)
[5]=> int(4)
}

Remember: Output of array_unique() will have the same key of input array.

Be Sociable, Share!

Leave a Reply