定义和用法
array_diff_ukey() 函数用于比较两个(或更多个)数组的键名 ,并返回差集。
注释:该函数使用用户自定义函数比较键名!
该函数比较两个(或更多个)数组的键名,并返回一个差集数组,该数组包括了所有在被比较的数组(array1)中,但是不在任何其他参数数组(array2 或 array3 等等)中的键名。
语法
array_diff_ukey(array1,array2,array3...,myfunction);
参数描述
array1 必需要有。与其他数组进行比较的第一个数组。
array2 必需要有。与第一个数组进行比较的数组。
array3,... 可选。与第一个数组进行比较的其他数组
myfunction 必需要有。一个定义了可调用比较函数的字符串。如果第一个参数 <, =, > 第二个参数,相应地比较函数必须返回一个 <, =, > 0 的整数。
返回值:
返回一个差集数组,该数组包括了所有在被比较的数组(array1)中,但是不在任何其他参数数组(array2 或 array3 等等)中的键名。
实例展示1:
<!DOCTYPE html>
<html>
<body>
<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"blue","b"=>"black","e"=>"blue");
$result=array_diff_ukey($a1,$a2,"myfunction");
print_r($result);
?>
</body>
</html>运行结果:
Array ( [c] => blue )
实例展示2:
<!DOCTYPE html>
<html>
<body>
<?php
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"black","b"=>"yellow","d"=>"brown");
$a3=array("e"=>"purple","f"=>"white","a"=>"gold");
$result=array_diff_ukey($a1,$a2,$a3,"myfunction");
print_r($result);
?>
</body>
</html>运行结果:
Array ( [c] => blue )
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!
Comment ouvrir le fichier php
Comment supprimer les premiers éléments d'un tableau en php
Que faire si la désérialisation php échoue
Comment connecter PHP à la base de données mssql
Comment connecter PHP à la base de données mssql
Comment télécharger du HTML
Comment résoudre les caractères tronqués en PHP
Comment ouvrir des fichiers php sur un téléphone mobile