Twin Prime Numbers between 1 and n | PHP program to print all twin primes using Sieve of Eratosthenes . ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; to check for twin prime numbers display the twin primes ; Driver Code ; Calling the function
< ? php function printTwinPrime ( $ n ) { $ prime = array_fill ( 0 , $ n + 1 , true ) ; for ( $ p = 2 ; $ p * $ p <= $ n ; $ p ++ ) { if ( $ prime [ $ p ] == true ) { for ( $ i = $ p * 2 ; $ i <= $ n ; $ i += $ p ) $ prime [ $ i ] = false ; } } for ( $ p = 2 ; $ p <= $ n - 2 ; $ p ++ ) if ( $ prime [ $ p ] && $ prime [ $ p + 2 ] ) echo " ( " . $ p . " , ▁ " . ( $ p + 2 ) . " ) " ; } $ n = 25 ; printTwinPrime ( $ n ) ; ? >