3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = "1 AND 2 -> a"; $inputs = explode("\n", $input); function operation($s){ $matchesand = null; $and = preg_match("/(.{1,2})\sAND\s(.{1,2})\s->\s(.{1,2})/",$s,$matchesand); if(count($matchesand)>0){ return [1,$matchesand[1] , $matchesand[2], $matchesand[3]]; } $matchesor= null; $or = preg_match("/(.{1,2})\sOR\s(.{1,2})\s->\s(.{1,2})/",$s,$matchesor); if(count($matchesor)>0){ return [2,$matchesor[1] , $matchesor[2], $matchesor[3]]; } $matchesnot = null; $not = preg_match("/NOT\s(.{1,2})\s->\s(.{1,2})/",$s,$matchesnot); if(count($matchesnot)>0){ return [3,$matchesnot[1], $matchesnot[2]]; } $matchesleft = null; $left = preg_match("/(.{1,2})\sLSHIFT\s(.{1,2})\s->\s(.{1,2})/",$s,$matchesleft); if(count($matchesleft)>0){ return [4,$matchesleft[1] , $matchesleft[2], $matchesleft[3]]; } $matchesright = null; $right = preg_match("/(.{1,2})\sRSHIFT\s(.{1,2})\s->\s(.{1,2})/",$s,$matchesright); if(count($matchesright)>0){ return [5,$matchesright[1] , $matchesright[2], $matchesright[3]]; } $matches = null; $simple = preg_match("/(.{1,5})\s->\s(.{1,2})/",$s,$matches); if(count($matches)>0){ return [6,$matches[1], $matches[2]]; } } $array=[]; for($i = 'a'; $i<'z'; $i++){ $array[$i]=0; } for($i = 'a'; $i<'z'; $i++){ for($j = 'a'; $j<'z'; $j++){ $array[$i.$j]=0; } } for($i = 0; $i<count($inputs); $i++){ $values = operation($inputs[i]); if($operation[0] === 1){ $array[$values[3]] = $array[$values[1]] & $array[$values[2]]; } $array[$var] = $val; } var_dump($array); ?>

preferences:
47.4 ms | 402 KiB | 5 Q