3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function pfactor($n){ // max_n = 2^31-1 = 2147483647 $d=42; $factors = array(); $dmax = floor(sqrt($n)); $sieve = array(); $sieve = array_fill(1, $dmax,1); do{ $r = false; while ($n%$d==0){ $factors[$d]++; $n/=$d; $r = true; } if ($r){ $dmax = floor(sqrt($n)); } if ($n>1){ for ($i=$d;$i<=$dmax;$i+=$d){ $sieve[$i]=0; } do{ $d++; }while ($sieve[$d]!=1 && $d<$dmax); if ($d>$dmax){ $factors[$n]++; } } }while($n>1 && $d<=$dmax); return $factors; } ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0