Array difference set for getting Started tutorial of PHP array

Source: Internet
Author: User
This article describes the PHP array to find the difference set of methods, with the need for a friend reference.

In PHP, find the difference set of arrays.

You need to use the difference set function for the array: Array_diff (). The PHP array function Array_diff () returns a value that appears in the first array but not in the other input array. This function is opposite to Array_intersect (). Array Array_diff (array Array1,array array2[,arrayn ...])

Let's look at a simple example:

 
      Banana)  ?>

Next, we introduce the method of PHP to take two arrays of difference set.

Then look at the definition and usage of the Array_diff () function.

The definition and usage of the Array_diff () function returns an array of difference sets for two arrays. The array includes all of the key values in the array being compared, but not in any other parameter array. In the returned array, the key name remains unchanged.

Grammar Array_diff (Array1,array2,array3 ...

Parameter description array1 required. The first array to compare with the other array. Array2 required. The array to compare with the first array. Array3 is optional. The array to compare with the first array.

Tip You can use one or any number of arrays to compare to the first array.

Note Only values are used for comparisons.

Example:

 
      "Cat",1=> "Dog",2=> "Horse");    $str 2=array (3=> "Horse",4=> "Dog",5=> "Fish");    $result = Array_diff ($str 1, $str 2);    Dump ($result);    To find array difference set by bbs.it-home.org?>

Output: Array 0=>string ' Cat ' (length=3)

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