Home >Backend Development >PHP Problem >How to get different values ​​in two arrays in php

How to get different values ​​in two arrays in php

王林
王林Original
2020-08-17 14:40:362653browse

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.

How to get different values ​​in two arrays in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn