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

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

藏色散人
Release: 2023-03-13 17:12:01
Original
2077 people have browsed it

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

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!

Related labels:
php
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