Συνάρτηση array_intersect_assoc() PHP

Παράδειγμα

Σύγκριση των ονομάτων κλειδιών και των τιμών δύο διανύσεων και επιστροφή της διανύσης σύγκρισης:

<?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);
?>

Run Instance

Ορισμός και χρήση

Η συνάρτηση array_intersect_assoc() χρησιμοποιείται για τη σύγκριση των ονομάτων κλειδιών και των τιμών των δύο (ή περισσότερων) διανύσεων και επιστρέφει τη διανύση σύγκρισης.

Η συνάρτηση αυτή συγκρίνει τα ονόματα κλειδιών και τις τιμές των δύο (ή περισσότερων) διανύσεων και επιστρέφει μια διανύση σύγκρισης, η οποία περιλαμβάνει όλες τις τιμές που βρίσκονται στις συγκριθείσες διανύσειςarray1in, as well as in any other parameter arrays (array2 or array3 etc.) key names and values.

Description

The array_intersect_assoc() function returns an intersection array of two or more arrays.

vs array_intersect( The difference between this function and the previous one is that it not only compares key values but also key names. The key names of the elements in the returned array remain unchanged.

Syntax

array_intersect_assoc(array1,array2,array3...)
Parameters Description
array1 Required. The first array to compare with other arrays.
array2 Required. The array to compare with the first array.
array3,... Optional. Other arrays to compare with the first array.

Technical Details

Return Value: Returns an intersection array that includes all key names and values from the compared arrays (array1in, as well as in any other parameter arrays (array2 or array3 etc.) key names and values.
PHP Version: 4.3.0+

More Examples

Example 1

Compare the key names and values of three arrays and return the intersection:

<?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);
?>

Run Instance