Home  >  Article  >  Backend Development  >  How to get different values ​​from two arrays in php

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

藏色散人
藏色散人Original
2021-11-03 10:53:002021browse

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.

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

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!

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