PHP determines whether the two-dimensional array retrieved from the database has duplicate values

angryTom
Release: 2023-04-07 15:42:02
forward
4284 people have browsed it

In project development, we sometimes need to know whether the data we find is duplicated. Generally, the data we find is two-dimensional data, so as long as one field is unique, we can judge. Simple accumulation and reduced duplication of work.

Go directly to the code

public function isRepeat(){
    // 微擎查数据库方法
    $list = pdo_getall('ewei_shop_member');
    $list = array_column($list,'openid');
    if (count($list) != count(array_unique($list))) {
        echo '该数组有重复值';
    }else{
        echo '该数组没有重复值';
    }
}
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of PHP determines whether the two-dimensional array retrieved from the database has duplicate values. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:www.whmblog.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