Is there a simple way to check if all values in array are equal to each other?
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?
Thanks in advance!
Not a single function, but the same could be achieved easily(?) with:
count(array_keys($array, 'yes')) == count($array)
another possible option
if(count(array_unique($array)) == 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With