PHP array_intersect_assoc() Function

Definition

The array_intersect_assoc() function compares the keys and values of two or more arrays and returns an array that contains the entries from array1 that are present in array2, array3, etc.

Syntax

PHP array_intersect_assoc() Function has the following syntax.

array_intersect_assoc(array1,array2,array3...)

Parameter

ParameterIs RequiredDescription
array1Required.Array to be compared with
array2Required.Array to be compared with array1
array3,...Optional.Array to be compared with array1

Return

PHP array_intersect_assoc() Function returns an array that contains the entries from array1 that are present in array2, array3, etc.

Example 1

Compare the keys and values of two arrays, and return the matches:


<?php//  w  w w  .j av  a2 s.  c om
$a1=array("a"=>"A","b"=>"B","c"=>"C","d"=>"Dog");
$a2=array("a"=>"B","b"=>"New B","c"=>"java2s.com");

$result=array_intersect_assoc($a1,$a2);
print_r($result);
?>

The code above generates the following result.

Example 2

Compare the keys and values of three arrays, and return the matches:


<?php//from   www . j  av a 2  s  .  co m
$a1=array("a"=>"A","b"=>"B","c"=>"C","d"=>"Dog");
$a2=array("a"=>"B","b"=>"New B","c"=>"java2s.com");
$a3=array("J"=>"java2s.com");

$result=array_intersect_assoc($a1,$a2,$a3);
print_r($result);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions