3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('memory_limit', -1); function find_primes($finish) { $number = 2; $range = range(2, $finish); $primes = array_combine($range, $range); while ($number * $number < $finish) { for ($i = $number; $i <= $finish; $i += $number) { if ($i == $number) { continue; } unset($primes[$i]); } $number = next($primes); } return $primes; } echo array_sum(find_primes(2000000));
Output for 7.0.0 - 7.0.14, 7.0.16 - 7.0.30, 7.0.32 - 7.0.33, 7.1.0 - 7.1.24, 7.1.26 - 7.1.33, 7.2.0 - 7.2.2, 7.2.9 - 7.2.25, 7.3.0, 7.3.2 - 7.3.12, 7.4.0, 8.2.18, 8.3.5 - 8.3.6
142913828922
Output for 8.2.17, 8.3.4
Fatal error: Out of memory (allocated 2097152 bytes) (tried to allocate 33554440 bytes) in /in/2NP03 on line 9 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.28
Fatal error: Out of memory (allocated 69210112) (tried to allocate 67108872 bytes) in /in/2NP03 on line 10 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 7.3.1
142913828922
Process exited with code 137.
Output for 5.6.33, 5.6.39, 7.0.15, 7.0.31, 7.1.25, 7.2.3 - 7.2.8

Process exited with code 137.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.32, 5.6.34 - 5.6.38, 5.6.40
Fatal error: Out of memory (allocated 260046848) (tried to allocate 32 bytes) in /in/2NP03 on line 9
Process exited with code 255.

preferences:
168.34 ms | 402 KiB | 199 Q