Friday 12 August 2016

PHP Function to Check Prime Number

Check if a given number is a prime number or not using this simple PHP script.
Make use of this simple php function to find whether the number is a prime number or not.

function checkPrimeNumber($number) {
    $string = str_repeat("1", $number);
    if(preg_match( '/^1?$|^(11+?)\1+$/', $string )==0) {
        return true;
    }
    return false;
}

No comments:

Post a Comment