PHP gets the intersection and difference set of the array
array_intersect () function reloaded from the http://www.nowamagic.net/librarys/posts/php/70
array returns an array of retained keys that consist of only the values that appear in the first array and appear in every other input array. Its form is as follows:
[code]array array_intersect (array array1, array array2.#91, arrayN... .#93) [/code]
this example will return all the fruits that appear in the $fruit1 array and appear in $fruit2 and $fruit3:
[code].Lt;? Php
$fruit1 = array. E.quot;);
$fruit3 = array (.Quot; Watermelon.quot;.Quot; Orange.quot;.Quot; Apple.quot;) Array_intersect () functions are considered to be the same when they are equal and have the same data type.
the intersection of the associative array array_intersect_assoc ()
function array_intersect_assoc () is basically the same as array_intersect (), but he also considers the key of the array in the comparison. Therefore, only key / value pairs that appear in the first array and appear in all other input arrays are returned to the result array. The form of
is as follows:
[code]array array_intersect_assoc (array array1, array array2.#91, arrayN... .#93) [/code]
the example below returns to appear in the $fruit1 array, and also all the keys / values in $fruit2 and $fruit3:
[code].Lt;? Php
$fruit1 = array. Br / > $fruit2 = array (.Quot; yellow.quot; =.gt;.Quot; Pear.quot;.Quot; red.quot; =.gt;.Quot. Intersection = array_intersect_assoc ($fruit1, $fruit2, $fruit3);
print_r ($intersection);
/ / > / / / / / Array.