Hi Guys,
Here, I will show you how to work php to check if the array has duplicate values. you can understand the concept of PHP and check if the array has the same values. you'll learn php to check if arrays have the same values. If you have a question about checking if the array contains duplicate values php laravel then I will give a simple example with a solution. we will use the count() function and array_unique() function to check check if the array has duplicate values in PHP. so, let's see the simple code of how to check duplicate values in array php.
Example:
index.php
<?php
$myArray = ['One', 'Two', 'Three', 'Two', 'Five', 'Three', 'One'];
if (count($myArray) !== count(array_unique($myArray))){
var_dump("Array has duplicate value.");
} else {
var_dump("Array dose not have duplicate value.");
}
?>
Output:
string(26) "Array has duplicate value."
I hope it can help you...
0 Comments
Leave a Comment