Home > Backend Development > PHP Tutorial > php-Arrays function-array_diff_key-calculate the difference of arrays using key name comparison_PHP tutorial

php-Arrays function-array_diff_key-calculate the difference of arrays using key name comparison_PHP tutorial

WBOY
Release: 2016-07-13 17:51:23
Original
1125 people have browsed it

array_diff_key() function calculates the difference set of an array using key name comparison

【Function】
This function will return an array,
This array contains the values ​​of all keys that are in array1 but are not in any other parameter array.
【Scope of use】
          >=5.1.0
【Use】
array array_diff_key( array array1, array array2[,array...] )
           array1/required/array1
           array2/required/comparable array must have at least one
           array.../optional/array used for comparison
【Example】
[php]

          $arr1 = array( "key1" => "val1", "key2" => "val2" );
          $arr2 = array( "key1" => "val1", "key3" => "val2" );
          $arr3 = array( "key2" => "val2" );
            print_r( array_diff_key( $arr1, $arr2 ) );
​​​​print_r( array_diff_key( $arr1, $arr3 ) );
            print_r( array_diff_key( $arr1, $arr2, $arr3 ) );
/*
Array
(
[key2] => val2
)
Array
(
[key1] => val1
)
Array
(
)
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478200.htmlTechArticlearray_diff_key() function uses key name comparison to calculate the difference set of the array [Function] This function will return an array, the The array contains all parameter arrays that are in array1 but not in any other parameter array...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template