Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php determine whether two arrays have the same value?

Shulou Source: shulou.com Published: 2022-05-31 16:55:31 09月30日 Update

This article introduces the knowledge of "how to judge whether two arrays have the same value". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Method: 1, use array_intersect () to compare the values of two arrays, syntax "array_intersect (array 1, array 2)", will return an intersection array; 2, determine whether the intersection array is empty, the syntax "intersection array = = []", if it is empty, there is no same value, if it is not empty, there is the same value.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php determines whether two arrays have the same value.

1. Use the array_intersect () function to compare two arrays to get the intersection elements

The array_intersect () function compares the values of two (or more) arrays and returns an intersecting array.

If two arrays have the same value, there are elements in the intersection array, not an empty array

If the two arrays do not have the same value, there are no elements in the intersection array, it is an empty array

2. Determine whether the intersection array is an empty array

If it is an empty array, the two arrays do not have the same value

If it is not an empty array, the two arrays have the same value

The intersection of array 1 and array 2 of echo:

"; $intersect=array_intersect ($arr1,$arr2); var_dump ($intersect); if ($intersect== []) {echo" two arrays do not have the same value

";} else {echo" two arrays have the same value

The intersection of ";} echo" array 2 and array 3:

"; $intersect=array_intersect ($arr3,$arr2); var_dump ($intersect); if ($intersect== []) {echo" two arrays do not have the same value

";} else {echo" two arrays have the same value

";}

That's all for "how php determines whether two arrays have the same value". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Array two same intersection element more content function knowledge grammar utility achievement next dilemma reality situation tutorial article method case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Linux Shulou Tech Info Xiaomi