PHP Arrays Simple intersection and difference sets and implementation examples of the function of the set

Source: Internet
Author: User
In this paper, we describe the simple intersection, difference set and set function of PHP implementation. Share to everyone for your reference, as follows:

<?PHP$ARR1 = Array (' 0 ' = ' zero ', ' 1 ' = ' = ' one ', ' 2 ' = ' + ', ' 3 ' = ' three '); $arr 2 = Array (' 2 ' = ' ", ' t Hree ' + ' three ', ' 4 ' = ' Four ', ' 5 ' = ' five ');//Difference Set "The comparison returns the values in ARR1 but not in the ARR2 and any other parameter arrays. "$array _diff = Array_diff ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _diff);/* Output Results *array* (* [0] = zero* [1] = one*) *///intersection "The comparison returns values that are both in arr1 and in the ARR2 array. Note: Key values remain arr1 the key values in the array are constant $array_intersect = Array_intersect ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _intersect);/* Output Result *array* (* [2] = two* [3] = three*) *///and set "append the values in the ARR1 array to the ARR2 array. Returns an array as the result. "#注意事项:" If the input array has the same string key name, the value following the key name overrides the previous value. #然而, if the array contains numeric key names, subsequent values will not overwrite the original values, but are appended to the back. "$array _merge = Array_merge ($arr 1, $arr 2); echo "<pre>"; Print_r ($array _merge);/* Output result * array* (* [0] = zero* [1] = = one* [2] = = two* [3] = = three* [4] = = two* [th REE] = three* [5] = four* [6] = = five*) */?>

Operation Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.