简体   繁体   English

如何检查php多维数组值是否相同?

[英]How to check php multidimensional array values are same or not?

My array is like this, 我的数组是这样的,

Array
(
    [0] => Array
        (
            [con_id] => 44
        )

    [1] => Array
        (
            [con_id] => 217
        )

    [2] => Array
        (
            [con_id] => 217
        )

    [3] => Array
        (
            [con_id] => 217
        )

    [4] => Array
        (
            [con_id] => 97
        )

)

I want to check all the con_id are the same then, return true or return false . 我要检查所有con_id是否相同,然后返回truefalse Is there any built-in function in php for doing this? 有没有内置的功能在PHP中做到这一点?

Thanks in advance. 提前致谢。

Just check count of unique elements. 只需检查唯一元素的数量即可。

$array = array(array('con_id'=>44),array('con_id'=>44),);
$result = count(array_unique($array, SORT_REGULAR))==1; 

var_dump($result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM