Primality Test | Set 1 ( Introduction and School Method ) | A school method based PHP program to check if a number is prime ; Corner case ; Check from 2 to n - 1 ; Driver Code
< ? php function isPrime ( $ n ) { if ( $ n <= 1 ) return false ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) if ( $ n % $ i == 0 ) return false ; return true ; } $ tet = isPrime ( 11 ) ? " ▁ true STRNEWLINE " : " ▁ false STRNEWLINE " ; echo $ tet ; $ tet = isPrime ( 15 ) ? " ▁ true STRNEWLINE " : " ▁ false STRNEWLINE " ; echo $ tet ; ? >