To find the difference of two maps in PHP, you can use the array_diff_assoc()
function. This function compares the keys and values of two arrays and returns an array containing all the entries from the first array that are not present in the second array.
Here's an example:
main.php130 chars7 lines
Output:
main.php36 chars6 lines
In this example, we have two maps ($map1
and $map2
). We want to find the entries in $map1
that are not present in $map2
, so we use array_diff_assoc()
to compare the two maps. The resulting array, $difference
, contains the entries [a] => 1
and [c] => 3
, which are the entries in $map1
that are not present in $map2
.
gistlibby LogSnag