3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new stdClass(); $obj->a = 5; $obj->b = 2; $obj->c = 9; $filter = array( 'logic' => 'AND', 'filters' => array( array('field' => 'a', 'operator' => '===', 'value' => 5), array( 'logic' => 'OR', 'filters' => array( array('field' => 'b', 'operator' => '===', 'value' => 6), array('field' => 'c', 'operator' => '<', 'value' => 10), ), ), ), ); function process(string $logic, array $filters, object $obj): bool { // For an AND, all things must be true, so if we're given 5 things, all 5 must be true. // For an OR, only one needs to be true. $targetCount = 'AND' === $logic ? count($filters) : 1; // How many items were true $currentCount = 0; foreach ($filters as $filter) { // The sub-array is a grouping, grab parts, process, and if true, increment our local counter if (array_key_exists('logic', $filter)) { if (process($filter['logic'], $filter['filters'], $obj)) { $currentCount++; } // For a sub-array, don't process anything else continue; } // Grab array items as variables just for ease of use $field = $filter['field']; $operator = $filter['operator']; $value = $filter['value']; // Match on the operator. For lower versions of PHP a switch(true) or just an if could be used, too. $result = match ($operator) { '===' => $obj->$field === $value, '==' => $obj->$field == $value, '>=' => $obj->$field >= $value, '>' => $obj->$field > $value, '<=' => $obj->$field <= $value, '<' => $obj->$field < $value, }; // If success, increment our counter if ($result) { $currentCount++; // If we've reach our target, return success // This could also just be "if process = OR" if ($currentCount === $targetCount) { return true; } } } // See if we met the final condition outside of the loop return $currentCount === $targetCount; } echo process($filter['logic'], $filter['filters'], $obj) ? 'yes' : 'no';

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0040.01119.06
8.3.30.0060.00918.63
8.3.20.0050.00324.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.170.0040.01119.04
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0000.00720.90
8.2.110.0040.00720.33
8.2.100.0060.00320.52
8.1.270.0060.00323.83
8.1.260.0000.00826.35
8.1.250.0000.00828.09
8.1.240.0030.00720.48
8.1.230.0100.00022.18
8.1.00.0110.00779.33
8.0.80.0070.00648.12

preferences:
48.6 ms | 400 KiB | 5 Q