PHP array_intersect_assoc()関数
例
2つの配列のキーと値を比較し、一致するものを返します。
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","c"=>"blue");
$result=array_intersect_assoc($a1,$a2);
print_r($result);
?>
定義と使用法
array_intersect_assoc()関数は、2つ(またはそれ以上)の配列のキーと値 を比較し、一致するものを返します。
この関数は、2つ以上の配列のキーと値を比較し、 array2、array3などに存在するarray1からのエントリを含む配列を返します。
構文
array_intersect_assoc(array1,array2,array3, ...)
パラメータ値
Parameter | Description |
---|---|
array1 | Required. The first array is the array that the others will be compared with |
array2 | Required. An array to be compared with the first array |
array3,... | Optional. An array to be compared with the first array |
技術的な詳細
戻り値: | 他のすべての配列に存在する array1からのエントリを含む配列を返します |
---|---|
PHPバージョン: | 4.3.0+ |
その他の例
例
3つの配列のキーと値を比較し、一致するものを返します。
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","g"=>"blue");
$a3=array("a"=>"red","b"=>"green","g"=>"blue");
$result=array_intersect_assoc($a1,$a2,$a3);
print_r($result);
?>
❮PHP配列リファレンス