1
2<?php
3$array1 = array("a" => "green", "red", "blue", "red");
4$array2 = array("b" => "green", "yellow", "red");
5$result = array_diff($array1, $array2);
6
7print_r($result);
8?>
9
10Array
11(
12 [1] => blue
13)
1<?php
2$arr_1 = array("a" => "car", "b" => "plane", "c" => "boat", "d" => "bike");
3$arr_2 = array("e" => "car", "f" => "plane", "g" => "boat");
4
5$result = array_diff($arr_1, $arr_2);
6print_r($result);
7
8/* Result:
9Array
10(
11 [d] => bike
12)
13 */
14
1<?php
2$array1 = array("a" => "green", "red", "blue", "red");
3$array2 = array("b" => "green", "yellow", "red");
4$result = array_diff($array1, $array2);
5?>
6
7Array
8(
9 [1] => blue
10)
1PHP function array_diff(array $array1, array $array2, array ...$_) int[]
2--------------------------------------------------------------------
3Computes the difference of arrays.
4
5Parameters:
6array--$array1--The array to compare from
7array--$array2--An array to compare against
8array--...$_--[optional]
9
10Returns: an array containing all the entries from array1 that are not present in any of the other arrays.