How to compare two array values in PHP?

How to compare two array values in PHP?

Asked on November 3, 2018 in PHP.
Add Comment


  • 1 Answer(s)

    Here the PHP array_diff() function is used to compare an array against one or more other arrays.

    The array_diff() function returns the values in the first array that are not present in any of the other arrays.

    For example:

    <?php
    $array1 = array("a" => "sky", "star", "moon", "cloud", "moon");
    $array2 = array("b" => "sky", "sun", "moon");
     
    // Comparing the values
    $result = array_diff($array1, $array2);
    print_r($result);
    ?>
    

     

    Answered on November 3, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.