Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Computes the difference of two or more arrays with additional index check

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 112
    Comment on it

    If you want to compute the difference of two or more than 2 array with index means to compare 2 array with the index of arrays for this you can use the predefined PHP function "array_diff_assoc()". array_diff_assoc() compares array1 against array2 and returns the difference as array.The difference with array_diff() is, the array keys used in the comparison.
    Here is a example which explain this-

    <?php
    $array1 = array("a" => "one", "b" => "two", "c" => "three", "four");
    $array2 = array("a" => "one", "two", "four");
    $result = array_diff_assoc($array1, $array2);
    print_r($result);
    ?>
    

    Output:

    Array
    (
        [b] => two
        [c] => three
        [0] => four
    )
    

    In this example "one" exist in both array with same index and "four" exist in both but key is different.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: