Get different elements in the array
php compares different elements in two arrays (recommended learning: PHP video Tutorial)
array array_diff(array $array1, array $array2, [, array $...]) array array_diff_assoc(array $array1, array $array2, [, array $...])
Similarly, the basic functions of these two methods are the same, returning elements that are in the first array but not in other arrays. The former only compares values, while the latter compares both key and value.
array_diff() function returns the difference array of two arrays. This array contains all keys that are in the array being compared, but are not in any of the other parameter arrays.
In the returned array, the key names remain unchanged.
<?php $array1 = array('1', 'a' => 'aaaaaa', 'b' => 'bbbbbb', 'c'); $array2 = array('a' => 'aaaaaa', 'c' => 'bbbbbb', 'c', '1'); var_dump(array_diff_assoc($array1, $array2));
Get the following results:
array(3) { [0]=> string(1) "1" ["b"]=> string(6) "bbbbbb" [1]=> string(1) "c" }
The above is the detailed content of php returns different elements in two arrays. For more information, please follow other related articles on the PHP Chinese website!