Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Computes the intersection of arrays

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 87
    Comment on it

    If you want to get all those values which exist in an array and also exist in other array means intersect values between an array and the set of other arrays then you can use a predefined php function array_intersect. array_intersect() returns an array containing all the values of array1 that are present in all the arguments.
    Note that keys are preserved.
    array_intersect returns an array containing all of the values in array1 whose values exist in all of the parameters.

    Here are a example which will explain array_intersect()-

    <?php
    $array1 = array("a" => "green", "red", "blue");
    $array2 = array("b" => "green", "yellow", "red");
    $result = array_intersect($array1, $array2);
    print_r($result);
    ?>
    

    Output:

    Array
    (
        [a] => green
        [0] => red
    )
    

 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: