Home >Backend Development >PHP Problem >How to get different values from two arrays in php
php method to obtain different values of two arrays: 1. Create a PHP sample file; 2. Define two different arrays; 3. Through "array_merge(array_diff($a,$b),array_diff( $b,$a));" method to obtain different values.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to get the difference between two arrays in php value?
php Get the different values between two arrays
The code is as follows:
$a = [1,2,3]; $b = [2,3,7,1,5]; $arr3 = array_merge(array_diff($a,$b),array_diff($b,$a));
array_merge() function merges one or more arrays into one array.
array_diff() function is used to compare the values of two (or more) arrays and return the difference.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to get different values from two arrays in php. For more information, please follow other related articles on the PHP Chinese website!