checking if n has any factor upto square root of n if yes its not prime
for ( $ i = 2 ; $ i <= $ root ; $ i ++ ) if ( $ n % $ i == 0 ) return false ; return true ; } function isSandwitched ( $ n ) { return ( isPrime ( $ n - 1 ) && isPrime ( $ n + 1 ) ) ; }