To find the intersection of two maps in PHP, you can use the array_intersect_key()
function or the array_intersect()
function.
The array_intersect()
function returns an array containing all the values of the first array that are present in all of the other arrays. To use array_intersect()
, you need to convert the maps to arrays using the array()
function.
main.php180 chars6 lines
The array_intersect_key()
function returns an array containing all the elements of the first array whose keys are present in all of the other arrays.
main.php193 chars6 lines
In the above example, the array_intersect_key()
function returns the elements of the first array whose keys are present in the second array.
gistlibby LogSnag