检查所有的数组值一次 [英] Checking all array values at once
本文介绍了检查所有的数组值一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法来检查,如果阵列中的所有值都彼此相等?
Is there a simple way to check if all values in array are equal to each other?
在这种情况下,将返回false:
In this case, it would return false:
$array[0] = 'yes';
$array[1] = 'yes';
$array[2] = 'no';
和在这种情况下,真实的:
And in this case, true:
$array[0] = 'yes';
$array[1] = 'yes';
$array[2] = 'yes';
所以,是的,是有一个函数/方法一次检查所有的数组值?
So, yeah, is there a function/method to check all array values at once?
在此先感谢!
推荐答案
不是一个单一的功能,但是同样可以用轻松实现(?):
Not a single function, but the same could be achieved easily(?) with:
count(array_keys($array, 'yes')) == count($array)
这篇关于检查所有的数组值一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文