English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
array_diff_assoc()Funktion vergleicht zwei (oder mehrere) Arrays und gibt die Differenz zurück.
Diese Funktion vergleicht zwei (oder mehrere) Arrays von Schlüsseln und Werten und gibt ein Array1Einträge, die in array2oder array3und ... fehlende Einträge in der Liste.
dieser Funktionarray_diff()Funktion, da array_diff() nur Werte mit anderen Arrays vergleicht, währendarray_diff_assoc()The function uses both keys and values when comparing with other arrays.
array array_diff_assoc(array $array1, array $array2 , array $array3];
Number | Parameters and Description |
---|---|
1 | array1 (required) is the array to be compared |
2 | array2 (required) It is the array to be compared with the first array |
3 | array3(optional) It is the array to be compared with the first array |
The array_diff_assoc() function returns an array that contains the array1contains all the values, which do not exist in any other array with the same key.
This function was first introduced in PHP version4.3introduced.
Try the following example. Both arrays contain "a" => "orange" and "c" => "banana", so they will not appear in the result-
<?php $input1 = array("a" => "orange", "b" => "mango", "c" => "banana"); $input2 = array("a" => "orange", "b" => "apple", "c" => "banana"); print_r(array_diff_assoc($input1, $input2); ?>Test and see‹/›
Output result:
Array ( [b] => mango )
Here, the two arrays have different keys and corresponding values for all pairs, for example, "a" => "orange" does not exist in the second array, similarly, other key-value pairs also do not exist in the second array, so they will be available in the result-
<?php $input1 = array("a" => "orange", "b" => "mango", "c" => "banana"); $input2 = array("a" => "banana", "b" => "apple", "c" => "orange"); print_r(array_diff_assoc($input1, $input2); ?>Test and see‹/›
Output result:
Array ( [a] => orange [b] => mango [c] => banana )
The following example illustrates that only when (string)$elem1 ===(string)$elem2are considered equal only when the two values in the key=>value pair are the same.
<?php $input1 = array(0, 5, 20); $input2 = array("00", "05", "20); $result = array_diff_assoc($input1, $input2); print_r($result); ?>Test and see‹/›
Output result:
Array ( [0] => 0 [1] => 5 )