php check if all array values are the same
if(count(array_unique($array)) === 1) {
// all values in $array are the same
} else {
// at least 1 value in $array is different
}
4.4
5
// All values are equal
if (count(array_unique($allvalues)) === 1 && end($allvalues) === 'true') {
}
// Check the thing you don't want
if (in_array('false', $allvalues, true)) {
}
Thank you!
5
0
3.75
8
1. Check if all values are equal without knowing the values from array:
$array = array('true', 'true', 'true');
if((count(array_unique($array)) === 1)) {
echo "all equal";
} else {
echo "not equal";
}
2. Check if all values are equal when you know the value from array:
- In this case we know the equal value should be "true"
$array = array('true', 'true', 'true');
if (count(array_unique($array)) === 1 && end($array) === 'true') {
}
Thank you!
8
0
Are there any code examples left?
New code examples in category PHP