php check if all values in array are the same code example
Example 1: check if all values in array are equal php
if(count(array_unique($array)) === 1) {
} else {
}
Example 2: php check if any of multiple values in array
function in_array_any($needles, $haystack) {
return !empty(array_intersect($needles, $haystack));
}
echo in_array_any( [3,9], [5,8,3,1,2] );
echo in_array_any( [4,9], [5,8,3,1,2] );
Example 3: php check if all values in array are equal
$allvalues = array('true', 'true', 'true');
if (count(array_unique($allvalues)) === 1 && end($allvalues) === 'true') {
}