Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda