Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check whether the values in an array are not equal to each other by php

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

The main content of this article is to explain "how php checks whether the internal values of arrays are not equal to each other". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "php how to check whether the internal values of arrays are not equal to each other".

Methods: 1, use "array_unique (array)" to remove the repeated values in the original array, will return a deduplicated array; 2, use count () to get the length of the original array, the length of the deduplicated array, syntax "count (array)"; 3, compare whether the two lengths are equal, if equal, the median values of the array are not equal, otherwise there are equivalent values.

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

Php checks that the values in the array are not equal to each other, that is, it checks whether the elements in the array have duplicate values; if there are duplicate values, the array elements are not equal to each other.

So how do you tell if the elements in the array have duplicate values?

Implementation method:

Use array_unique () to remove duplicate values from the original array and return the deduplicated array

Use count () to get the length of the original array and the length of the deduplicated array, respectively

Compare whether the original array length and the deduplicated array length are equal

If equal, it means that there are no duplicate values, that is, the values in the original array are not equal to each other.

If it is not equal, it means that there are duplicate values, that is, there are equivalent values in the original array.

Implementation example:

Determine whether the median values of the following arrays are not equal to each other.

$arr1=array (2, 3, 5, 5, 3, 2, 2, 1, 1, 2, 4); $arr2=array (3, 4, 5, 6, 7, 8, 8, 9, 1, 2)

Code:

You can see that there are equal values in the $arr1 array, and the values in the $arr2 array are not equal to each other.

At this point, I believe you have a deeper understanding of "php how to check whether the internal values of the array are not equal to each other". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report