比较键两个数组,并返回差异:
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","c"=>"blue","d"=>"pink");
$result=array_diff_key($a1,$a2);
print_r($result);
?>
亲自试一试 »
array_diff_key() 函数比较按键两个(或多个)数组,并返回差异。
此函数比较两个(或多个)数组的键,并返回一个包含以下条目的数组数组1不存在于数组2或者数组3, ETC。
array_diff_key(
array1, array2, array3, ...)
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,... | Optional. More arrays to compare against |
返回值: | 返回一个包含条目的数组数组1不存在于任何其他数组中 |
---|---|
PHP 版本: | 5.1+ |
比较键两个索引数组,并返回差异:
<?php
$a1=array("red","green","blue","yellow");
$a2=array("red","green","blue");
$result=array_diff_key($a1,$a2);
print_r($result);
?>
亲自试一试 »
比较键三个数组,并返回差异:
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("c"=>"yellow","d"=>"black","e"=>"brown");
$a3=array("f"=>"green","c"=>"purple","g"=>"red");
$result=array_diff_key($a1,$a2,$a3);
print_r($result);
?>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!