An interesting solution to get all prime numbers smaller than n | PHP program to prints prime numbers smaller than n ; Compute factorials and apply Wilson 's  theorem. ; Driver code
< ? php function primesInRange ( $ n ) { $ fact = 1 ; for ( $ k = 2 ; $ k < $ n ; $ k ++ ) { $ fact = $ fact * ( $ k - 1 ) ; if ( ( $ fact + 1 ) % $ k == 0 ) print ( $ k . " STRNEWLINE " ) ; } } $ n = 15 ; primesInRange ( $ n ) ; ? >