Home  >  Article  >  Backend Development  >  How to determine whether two arrays are different in php

How to determine whether two arrays are different in php

Guanhui
GuanhuiOriginal
2020-05-08 17:36:343042browse

How to determine whether two arrays are different in php

How to determine if two arrays are different in php

First use the function "array_diff()" to obtain the difference between the two arrays. This function The function is to calculate the difference between two or more arrays, and then determine the difference between the two returned arrays. If it is not empty, the two arrays are not the same.

Code example:

$array_a = ['a', 'b', 'c', 'u'];

$array_b = ['a', 'b', 'c'];

$diff = array_diff($array_a, $array_b);

var_dump($diff);

The output result is:

array(3=>'u')

Recommended tutorial: "PHP Tutorial

The above is the detailed content of How to determine whether two arrays are different 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