3v4l.org

run code in 300+ PHP versions simultaneously
<?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); ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: Unsupported operand types: string << string in /in/l53Fb:34 Stack trace: #0 /in/l53Fb(58): operation('x LSHIFT 2 -> f') #1 {main} thrown in /in/l53Fb on line 34
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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.3.32 - 7.3.33
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 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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
157.08 ms | 402 KiB | 200 Q