php - How to find unique values in array -


here want find unique values,so writing code can't answer,for me don't want array format.i want string

<?php  $array = array("kani","yuvi","raja","kani","mahi","yuvi") ;  $unique_array = array(); // unique array  $duplicate_array = array(); // duplicate array  foreach ($array $key=>$value){    if(!in_array($value,$unique_array)){         $unique_array[$key] = $value;    }else{       $duplicate_array[$key] = $value;    }    }    echo "unique values are:-<br/>";    echo "<pre/>";print_r($unique_array);      echo "duplicate values are:-<br/>";    echo "<pre/>";print_r($duplicate_array);    ?>

you can use array_unique() in single line below:-

<?php  $unique_array = array_unique($array); // unique value initial array  echo "<pre/>";print_r($unique_array); // print unique values array ?> 

output:- https://eval.in/601260

reference:- http://php.net/manual/en/function.array-unique.php

if want in string format:-

echo implode(',',$final_array); 

output:-https://eval.in/601261

the way want here:-

https://eval.in/601263

or

https://eval.in/601279


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -