3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); function get_primes7($n) { if ($n < 2) return array(); if ($n == 2) return array(2); $s = range(3, $n, 2); $mroot = sqrt($n); $half = count($s); $i = 0; $m = 3; while ($m <= $mroot) { if ($s[$i]) { $j = (int)(($m*$m - 3) / 2); $s[$j] = 0; while ($j < $half) { $s[$j] = 0; $j += $m; } } $i = $i + 1; $m = 2*$i + 3; } $res = array(2); foreach ($s as $v) { if ($v) { $res[] = $v; } } return $res; } $res = array(); for ($i = 1; $i <= 10; ++$i) { $res = get_primes7(10000); print "Found ".count($res)." prime numbers.\n"; }
based on FdRE8
Output for 5.4.34 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers.
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.0 - 5.4.32
Warning: ini_set() has been disabled for security reasons in /in/DaAJ6 on line 3 Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers. Found 1229 prime numbers.
Output for 4.3.5 - 4.3.10, 4.4.0 - 4.4.9
Warning: ini_set() has been disabled for security reasons in /in/DaAJ6 on line 3 Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers.
Output for 4.3.11
Warning: ini_set() has been disabled for security reasons in /in/DaAJ6 on line 3 Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Found 1 prime numbers.
Output for 4.3.1 - 4.3.4
Warning: ini_set,pcntl_fork() has been disabled for security reasons in /in/DaAJ6 on line 3 Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers.
Output for 4.3.0
Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers. Warning: Wrong parameter count for range() in /in/DaAJ6 on line 8 Warning: Invalid argument supplied for foreach() in /in/DaAJ6 on line 26 Found 1 prime numbers.