Skip to content

Instantly share code, notes, and snippets.

@lablnet
Created December 30, 2018 03:13
Show Gist options
  • Save lablnet/51846acefb2f4b3c49e34dbecad1ec4f to your computer and use it in GitHub Desktop.
Save lablnet/51846acefb2f4b3c49e34dbecad1ec4f to your computer and use it in GitHub Desktop.
Determine whether the given number is prime or not
<?php
function isPrime($n)
{
for ($i = 2; $i < $n ; $i++) {
if ($n % $i === 0){
return false;
}
}
return true;
}
//Usage
var_dump(isPrime(9)); // bool(false)
var_dump(isPrime(11)); // bool(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment