Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
How to make multiple conditions in PHP

I have few conditions there can be either 0 or more I want to go through the array if there are conditions and create a callback function that I will call in the filter and override one parameter

$f = function ($value) use ($array, $key) {
            return in_array($value->{$key}, $array[$key]);
        };
        array_push(self::$conditions, $f);

I didn't think of anything better than putting all the conditions in an array and then pulling them out in a loop like this

 public static function isPersonСorrespondsRequirements($people)
{
    $result = true;
    for($i = 0; $i < count(self::$conditions); $i++) {
        $result &= self::$conditions[$i]($people);
    };

    return count(self::$conditions) > 0 ? $result : false;
}

in short, I want to get the result from the isPersonСorrespondsRequirements function, which will be compiled according to the conditions stored in the $conditions array and it will be called like this

$tmp = $array->filter(function ($value, $key) {
                        if (NeedMapper::isPersonСorrespondsRequirements($value)) {
                            return $value;
                        }
                    });

P.S. I work with laraver, cause function filter it is collection method

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda