How to delete duplicates in php array ?

by THavamani 2013-05-04 15:24:28

Try it..

<?php
$array = array('1','1','2','3');

foreach($array as $data){
$key= array_keys($array,$data);
if(count($key)>1){

foreach($key as $key2 => $data2){
unset($array[$key2]);
}
}
}
$array=array_values($array);
print_r($array);


?>


Input:
$array = array('1','1','2','3');

Output:
$array = array('2','3');
210
like
0
dislike
0
mail
flag

You must LOGIN to add comments
Guna

Why dont you use array_unique()?

pinnureenga boss. nangallem ennekku thozhila kaththukka poromo.

Guna

ithu ulagamaha nadipuda saami...