Home >Backend Development >PHP Problem >How to get different values in two arrays in php
php method to obtain different values in two arrays: first use the array_diff() function to compare the values of the two arrays and return the difference set of the two arrays; then use the array_merge() function to compare the returned difference Just merge the sets into an array.
array_merge() function is used to merge one or more arrays into one array and return the merged array.
(Recommended tutorial: php graphic tutorial)
Syntax:
array_merge(array1,array2,array3...)
array_diff() function is used to compare two (or more ) value of the array and returns the difference set.
(Video tutorial recommendation: php video tutorial)
Grammar:
array_diff(array1,array2,array3...);
Implementation code:
$a = [1,2,3]; $b = [2,3,7,1,5]; $arr3 = array_merge(array_diff($a,$b),array_diff($b,$a));
The above is the detailed content of How to get different values in two arrays in php. For more information, please follow other related articles on the PHP Chinese website!