3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $sInput = 'toggle 0,0 through 999,0'; $aLights = array(); for($x = 0; $x < 1000; $x++) { for($y = 0; $y < 1000; $y++) { $aLights[$x . 'x' . $y] = false; } } $aInput = explode("\r\n", $sInput); foreach($aInput as $sInput) { preg_match('#(?<action>turn (?:on|off)|toggle) (?<from_x>[0-9]{1,3}),(?<from_y>[0-9]{1,3}) through (?<to_x>[0-9]{1,3}),(?<to_y>[0-9]{1,3})#', $sInput, $aMatch); for($x = $aMatch['from_x']; $x <= $aMatch['to_x']; $x++) { for($y = $aMatch['from_y']; $y <= $aMatch['to_y']; $y++) { switch($aMatch['action']) { case 'turn on': $aLights[$x . 'x' . $y] = true; break; case 'turn off': $aLights[$x . 'x' . $y] = false; break; case 'toggle': $aLights[$x . 'x' . $y] = ($aLights[$x . 'x' . $y] ? false : true); break; } } } } echo count(array_filter($aLights));
based on PBmXX
Output for 7.0.0 - 7.2.0
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 37748736 bytes) in /in/cVVXk on line 10
Process exited with code 255.
Output for 5.3.20 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 79 bytes) in /in/cVVXk on line 10
Process exited with code 255.