Php array Getting Started Tutorial-intersection of correlated arrays

Source: Internet
Author: User
Php array Getting Started Tutorial-intersection of correlated arrays
This article describes how to find the intersection of correlated arrays in a php array. For more information, see.

The php function array_intersect_assoc () is basically the same as array_intersect (), except that the array key is also considered during comparison. Therefore, only key/value pairs that appear in the first array and also appear in all other input arrays are returned to the result array.

The format is as follows: array array_intersect_assoc (array array1, array array2 [, arrayN…])

In this example, all key/value pairs that appear in the $ fruit1 array and $ fruit2 and $ fruit3 are returned:

     "Apple", "yellow" => "Banana", "orange" => "Orange"); $ fruit2 = array ("yellow" => "Pear ", "red" => "Apple", "purple" => "Grape"); $ fruit3 = array ("green" => "Watermelon ", "orange" => "Orange", "red" => "Apple"); $ intersection = array_intersect_assoc ($ fruit1, $ fruit2, $ fruit3); print_r ($ intersection ); // by bbs.it-home.org // output // Array ([red] => Apple)?>

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.