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

print_r($result);

/
Array
(
[1] => blue
)
/
?>
Have no the Yellow why?

    if you look in array1...

    there you have the colors:
    green
    red (2 times)
    blue

    and then in array2, you have these colors:
    green
    yellow
    red

    wich one of the colors in array1, does not exist in array2 ?
    yup, it's the color blue.

    Q: wich one of the colors in array2, does not exist in array1 ? 😃

      array_diff() returns an array containing all the values of array1 that are not present in array2

      array_diff($array2, $array1)

      will return Yellow only.

      it is just like 5-3 = 2 and 3-5 = -2

        toxic_brain wrote:

        array_diff() returns an array containing all the values of array1 that are not present in array2

        array_diff($array2, $array1)

        will return Yellow only.

        it is just like 5-3 = 2 and 3-5 = -2

        ...or simply just because the yellow color doesnt exist among the colors in array1 😃

          Write a Reply...