- sqrt: documentation ( source)
<?php
$primes = array();
$found = 0;
for ($x = 2; $x <= 100000; $x++) {
$xIsPrime = TRUE;
$sqrtX = sqrt($x);
foreach ($primes as $prime) if ($prime > $sqrtX || ((!($x % $prime)) && (!$xIsPrime = FALSE))) break;
if ($xIsPrime) $found++;
}
echo $found;