I want to check whether my array holds duplicate entry and if it holds duplicate values then remove those duplicate value.
This code will directly remove the duplicate value from an Array.
1. Remove duplicate values from an array
<?php
$arrUnique = array_unique ($array1);
?>
This array_unique function work in this manner-
(String)element1 = (string)element2;
String representation of each value will be checked.
2. Check whether an array holds duplicate values
<?php
if (count(array_unique($arr3)) < count($arr3))
echo 'Duplicate entry in array';
else
echo 'No Duplicate values in array';
?>
So, after combining both codes, I can check and be assured that I have unique values in my array.
Related: PHP array - Common functions
# 1 - by rupesh
hi satya prakash
It was nice to read ur code for checking duplicate values in array.
Thanks
rupesh
PHP developer
Gurgaon, India