3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function generatePrimesA($n) { $primes = [2]; for ($i = 3; $i < $n; $i += 2) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; } return $primes; } function generatePrimesB($max) { $primes = range(2, $max); for ($i = 0; pow($primes[$i], 2) < $max; $i++) { $prime = $primes[$i]; $primes = array_filter($primes, function($p) using ($prime) { return $p % $prime == 0; }); } return $primes; } var_dump(count(generatePrimesA(1000))); var_dump(count(generatePrimesB(1000))); var_dump(array_diff(generatePrimesA(1000), generatePrimesB(1000)));
Output for 5.4.0 - 5.4.26
Parse error: syntax error, unexpected 'using' (T_STRING), expecting '{' in /in/CckaJ on line 24
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[' in /in/CckaJ on line 4
Process exited with code 255.