Skip to content

Instantly share code, notes, and snippets.

@HoangPV
Created September 20, 2017 08:00
Show Gist options
  • Save HoangPV/63e88a6bbdfd1691cd21d51e5b0394bd to your computer and use it in GitHub Desktop.
Save HoangPV/63e88a6bbdfd1691cd21d51e5b0394bd to your computer and use it in GitHub Desktop.
checks if a number is prime
<?php
/**
* checks if a number is prime
*
* @return bool
* @author Phan Vu Hoang <[email protected]>
*/
function la_snt( $n ) {
if($n < 2) return false;
if($n == 2) return true;
if($n%2==0) return false;
for ($i=3; $i <$n-1 ; $i+=2) {
if($n%$i==0) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment