Getting started with php array: finding the difference set of correlated arrays

Source: Internet
Author: User
Getting started with php array: finding the difference set of correlated arrays
This article describes how to find the correlated array difference set in the php array, mainly the usage of the php array function array_diff_assoc. For more information, see.

In php, evaluate the difference set of the correlated array.

The array_diff_assoc () function is basically the same as the array_diff () function, except that the array key is also considered during comparison. Therefore, only key/value pairs that appear in the first array instead of other input arrays are returned to the result array.

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

In this example, only [yellow] => Banana is returned, because this special key/value pair exists in $ fruit1, and does not exist in $ fruit2 or $ fruit3.

     "Apple", "yellow" => "Banana", "orange" => "Orange"); $ fruit2 = array ("yellow" => "Pear ", "red" => "Apple", "purple" => "Grape"); $ fruit3 = array ("green" => "Watermelon ", "orange" => "Orange", "red" => "Apple"); $ intersection = array_diff_assoc ($ fruit1, $ fruit2, $ fruit3); print_r ($ intersection ); // output // Array ([yellow] => Banana)?>

Note: When traversing an array in php, you usually need to traverse the array and obtain each key or value (or simultaneously obtain the key and value). PHP provides some functions to meet your needs. Many functions can complete two tasks, not only to obtain the key or value of the current pointer position, but also to move the pointer to the next appropriate position.

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.