PHP gets the intersection and difference set of the array

time:13-06-16 forum:PHP tools and code
  The intersecting array_intersect ()

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.
  • 2

prev:PHP determines to compare the data in tw... next:The difference of PHP array traversal (i...
post comment
Notice



approved   Ji'nan free Scenic Area   What is the living condition of the ...   The family photo played by their par...   The universal Handbook of life in Ji...   Dr. doctorate: two hands earn money ...
rand   PHP implements code conversion betwe...   Capture the HTML content of the web ...   Three MYSQL client management tools   The universal Handbook of life in Ji...   Dr. doctorate: two hands earn money ...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com