Kani R Kani R - 1 year ago 150
HTML Question

How to find unique values in array

Here i want to find

values,so i am writing code like this but i can't get answer,for me don't want to array format.i want only string

$array = array("kani","yuvi","raja","kani","mahi","yuvi") ;
$unique_array = array(); // unique array
$duplicate_array = array(); // duplicate array
foreach ($array as $key=>$value){
$unique_array[$key] = $value;
$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);


Answer Source

You can use array_unique() in single line like below:-


$unique_array = array_unique($array); // get unique value from 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 you want in string format:-

echo implode(',',$final_array);


The way you want is here:-




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download