Yogirajsinh Jethwa Yogirajsinh Jethwa - 23 days ago 8
PHP Question

Array remove duplicate values

Hii m having array having duplicate values is there any way i can remove it?

<?php
$a1=array("abc"=>"1","def"=>"2","ghi"=>"3","hij"=>"2","dkm"=>"1","mik"=>"5");
?>


// output should be like 1,2,3,5

Answer

try this one....

<?php 
  $a1=array("abc"=>"1","def"=>"2","ghi"=>"3","hij"=>"2","dkm"=>"1","mik"=>"5"); 
  echo implode(',', array_unique($a1));
  // output = 1,2,3,5
?>
Comments