3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = "123 -> x 456 -> y x AND y -> d x OR y -> e x LSHIFT 2 -> f y RSHIFT 2 -> g NOT x -> h NOT y -> i"; $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 [$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 [$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 [~$matchesand[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 [$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 [$matchesright[1] >> $matchesright[2], $matchesright[3]]; } $matches = null; $simple = preg_match("/(.{1,5})\s->\s(.{1,2})/",$s,$matches); if(count($matches)>0){ return [$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++){ $var = operation($inputs[$i])[1]; $val = operation($inputs[$i])[0]; $array[$var] = $val; } var_dump($array); ?>
based on Z1ZTY
Output for 7.1.0 - 7.2.0
Warning: A non-numeric value encountered in /in/l53Fb on line 34 Warning: A non-numeric value encountered in /in/l53Fb on line 34 Warning: A non-numeric value encountered in /in/l53Fb on line 39 Warning: A non-numeric value encountered in /in/l53Fb on line 39 Notice: Undefined offset: 1 in /in/l53Fb on line 28 Fatal error: Uncaught Error: Unsupported operand types in /in/l53Fb:28 Stack trace: #0 /in/l53Fb(58): operation('NOT x -> h') #1 {main} thrown in /in/l53Fb on line 28
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Notice: Undefined offset: 1 in /in/l53Fb on line 28 Fatal error: Uncaught Error: Unsupported operand types in /in/l53Fb:28 Stack trace: #0 /in/l53Fb(58): operation('NOT x -> h') #1 {main} thrown in /in/l53Fb on line 28
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Notice: Undefined offset: 1 in /in/l53Fb on line 28 Fatal error: Unsupported operand types in /in/l53Fb on line 28
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/l53Fb on line 16
Process exited with code 255.