i want to print array duplicate, example :
$input = ['a', 'a', 'b'];
$output = array_unique($input);
echo $output;
i run code in php online ,but output just like this..
Array
how to echo "A" because "A" is duplicate alphabet from array above ?
i want to print array duplicate, example :
$input = ['a', 'a', 'b'];
$output = array_unique($input);
echo $output;
i run code in php online ,but output just like this..
Array
how to echo "A" because "A" is duplicate alphabet from array above ?
Your code works, you just cannot print an entire array with 'echo' statements. As written, you can print individual elements of $output (for example echo $output[0]; or echo $output[1];). If you want to print the whole array, use print_r($output); or var_dump($output);
Array_unique will not give you that information, it will only delete the duplicates.
If you count the values with array_count_values then use array_diff to get what is not 1, then the code will return the duplicated items.
But it will return them in keys, so use array_keys to get them as values.
$input = ['a', 'a', 'b'];
$count = array_count_values($input);
$duplicated = array_keys(array_diff($count, [1]));
var_export($duplicated);
You can also echo the duplicates with:
echo implode(", ", $duplicated);
Just use array_diff or array_diff_assoc for compute two array. (before and after doing remove duplicate by using array_unique)
Example :
$array = ['a','b','c'];
$array2 = $array;
echo "<pre>";
var_dump($array);
echo "</pre>";
$array = array_unique($array);
$diff = array_diff_assoc($array2,$array);
echo '<hr>Diff : ';
echo "<pre>";
var_dump($diff);
echo "</pre>";
exit();
See the result here.