3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = "turn off 499,499 through 500,500"; $lights = [[]]; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ $lights[$i][$j] = 0; } } $inputs = explode("\n",$input); function action($s){ $on = preg_match("/turn on/",$s); $off = preg_match("/turn off/",$s); $toggle = preg_match("/toggle/",$s); if($on > 0){ return 1; } else if($off>0){ return 2; } else if($toggle>0){ return 3; } } for($i = 0; $i < count($inputs); $i++){ $matches = null; preg_match_all("/\d{1,3},\d{1,3}/",$inputs[$i], $matches); $from = $matches[0][0]; $to = $matches[0][1]; $x1 = explode(",",$from)[0]; $y1 = explode(",",$from)[0]; $x2 = explode(",",$to)[0]; $y2 = explode(",",$to)[1]; for($j = $y1; $j<=$y2; $j++){ for($k = $x1; $k<=$x2; $k++){ if(action($inputs[$i])===1){ $lights[$j][$k] = 1; } else if(action($inputs[$i])===2){ $lights[$j][$k] = 0; } else if(action($inputs[$i])===3){ if($lights[$j][$k] === 0){ $lights[$j][$k] = 1; } else{ $lights[$j][$k] = 0; } } } } } $count = 0; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ if($lights[$i][$j] === 1){ $count++; } } } echo $count; ?>
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.1, 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
0
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 0
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 31457280) (tried to allocate 36864 bytes) in /in/6YAQf on line 8 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/6YAQf on line 8
Process exited with code 255.

preferences:
221.08 ms | 401 KiB | 330 Q