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

王林
Release: 2023-03-04 16:26:02
Original
2615 people have browsed it

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...)
Copy after login

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...);
Copy after login

Implementation code:

$a = [1,2,3];
$b = [2,3,7,1,5];
$arr3 = array_merge(array_diff($a,$b),array_diff($b,$a));
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template