Skip to content

Instantly share code, notes, and snippets.

@gumeniukcom
Created April 11, 2015 08:57
Show Gist options
  • Save gumeniukcom/f530615f34409f6a025e to your computer and use it in GitHub Desktop.
Save gumeniukcom/f530615f34409f6a025e to your computer and use it in GitHub Desktop.
<?php
/**
* @author Stan Gumeniuk [email protected]
*/
function getPrimeNumbers($n = 100)
{
$resheto = [];
$current = 2;
$build = 1;
while((count($resheto)+1)<=$n){
foreach($resheto as $prime){
if ($current%$prime!=0){
$build++;
}
}
if (count($resheto)+1==$build){
$resheto[] = $current;
}
$build = 1;
$current++;
}
return $resheto;
}
var_dump(getPrimeNumbers(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment