Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!