PHP array_intersect_key () function example tutorial

Source: Internet
Author: User

Let's take a look at PHP today.Array_intersect_key ()For the function instance tutorial, let's take a look at its simple description, and then look at the tutorial.

Array_intersect_key ()Definition and usage
The array_intersect_key () function compares two or more arrays, and returns the entry and value of an array from the first array, only in the Key currently on all other arrays.

Syntax

array_intersect_key(array1,array2,array3...)
 
Parameter Description
Array1 Required. The first array will work with other
Array2 Required. An array is relative to the first array.
Array3 Optional. An array is relative to the first array.

Tips and instructions
Tip: You can compare the first array with an array, or you like it.

Note: Only the key is the comparison.




Example 1

<?php$a1=array(0=>"Cat",1=>"Dog",2=>"Horse");$a2=array(2=>"Bird",0=>"Cat",4=>"Fish");print_r(array_intersect_key($a1,$a2));?>
 
The output data is.
Array ( [0] => Cat [2] => Horse )
 
Now let's take a look at instance 2.
 
<?php$a1=array(0=>"Cat",1=>"Dog",2=>"Horse");$a2=array(2=>"Bird",3=>"Rat",4=>"Fish");$a3=array(2=>"Dog",6=>"Cow",7=>"Bird");print_r(array_intersect_key($a1,$a2,$a3));?>
 
Output result.
Array ( [2] => Horse )

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.