“Como verificar se todos os valores em uma matriz são iguais php” Respostas de código

Verifique se todos os valores na matriz são iguais php

if(count(array_unique($array)) === 1) {
    // all values in $array are the same
} else {
    // at least 1 value in $array is different
}

PHP Verifique se todos os valores da matriz são os mesmos

// 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)) {

}
SantiBM

PHP Verifique se todos os valores na matriz são iguais

$allvalues = array('true', 'true', 'true');
if (count(array_unique($allvalues)) === 1 && end($allvalues) === 'true') {
}
Lypsoty112

Como verificar se todos os valores em uma matriz são iguais php

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') {
}
Sergiu The Man

Respostas semelhantes a “Como verificar se todos os valores em uma matriz são iguais php”

Perguntas semelhantes a “Como verificar se todos os valores em uma matriz são iguais php”

Procure respostas de código populares por idioma

Procurar outros idiomas de código