3v4l.org

run code in 300+ PHP versions simultaneously
<?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) use ($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 git.master, git.master_jit, rfc.property-hooks
int(168) Warning: Undefined array key 1 in /in/RBGZU on line 21 Warning: Undefined array key 1 in /in/RBGZU on line 22 Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /in/RBGZU:24 Stack trace: #0 [internal function]: {closure}(2) #1 /in/RBGZU(24): array_filter(Array, Object(Closure)) #2 /in/RBGZU(31): generatePrimesB(1000) #3 {main} thrown in /in/RBGZU on line 24
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.39 ms | 401 KiB | 8 Q