3v4l.org

run code in 300+ PHP versions simultaneously
<?php $query_input = [ '_or'=>[ ['cats'=>1], ['dogs'=>1] ] ]; $results = [ ['cats'=>0,'dogs'=>0], ['cats'=>0,'dogs'=>0,'lizards'=>3], ['cats'=>0,'dogs'=>1], ['cats'=>1,'dogs'=>0], ['cats'=>1,'dogs'=>1] ]; // hackkk both the filter and find methods need significant cleanup if (isset($query_input['_or'])) { foreach ($query_input['_or'] as $key=>$value) { $query_where = [$key, '_OR', null]; } } $out = []; $skip = []; foreach ($results as $result) { foreach ($query_where as $where) { list($key, $comp, $value) = $where; if (!isset($result[$key])) { $skip = ['!isset', $key]; continue; } // the data is not in the result, skip check switch ($comp) { case '_OR': foreach ($query_input['_or'][$key] as $or_item) { foreach ($or_item as $comp_key=>$comp_value) { if ($result[$comp_key] != $comp_value) { continue(2); } } break; // as long as the script hits here, the result will be kep } break; case '=': if ($result[$key] != $value) { $skip[] = [$result[$key],$value,'=',$key]; continue(3); } break; case 'LIKE': $pos = strpos($value,'%'); if ($pos===false) $pos = strlen($value); if (substr($result[$key],0,$pos) !== substr($value,0,$pos)) { $skip[] = [$result[$key],$value,'LIKE',$key]; continue(3); } break; } } } $out[] = $result; var_dump($out);
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { [0]=> array(2) { ["cats"]=> int(1) ["dogs"]=> int(1) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.33 ms | 401 KiB | 8 Q