PHP Check If Array Has Duplicate Values

PHP Check If Array Has Duplicate Values

  • Post category:PHP
  • Post comments:0 Comments

Here, I will show you how to work php check if array has duplicate values. you can understand a concept of php check if array has same values. you’ll learn php check if arrays have same values. If you have a question about check if array contains duplicate values php laravel then I will give a simple example with a solution. You Can Learn How to Get First Day of Month from Date in PHP?

we will use count() function and array_unique() function to check check if array has duplicate values in php. so, let’s see the simple code of how to check duplicate values in array php.

PHP Check If Array Has Duplicate Values 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..

Leave a Reply