Emirp numbers | Function to find reverse of any number ; Sieve method used for generating emirp number ( use of sieve ofEratosthenes ) ; 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 ; Traverse all prime numbers ; Find reverse a number ; A number is emrip if it is not a palindrome number and its reverse is also prime . ; Mark reverse prime as false so that it 's  not printed again ; Driver Code
< ? php function reverse ( $ x ) { $ rev = 0 ; while ( $ x > 0 ) { $ rev = ( $ rev * 10 ) + $ x % 10 ; $ x = ( int ) ( $ x / 10 ) ; } return $ rev ; } function printEmirp ( $ n ) { $ prime = array_fill ( 0 , ( $ n + 1 ) , 1 ) ; for ( $ p = 2 ; $ p * $ p <= $ n ; $ p ++ ) { if ( $ prime [ $ p ] == 1 ) { for ( $ i = $ p * 2 ; $ i <= $ n ; $ i += $ p ) $ prime [ $ i ] = 0 ; } } for ( $ p = 2 ; $ p <= $ n ; $ p ++ ) { if ( $ prime [ $ p ] == 1 ) { $ rev = reverse ( $ p ) ; if ( $ p != $ rev && $ rev <= $ n && $ prime [ $ rev ] == 1 ) { echo $ p . " " ▁ . ▁ $ rev ▁ . ▁ " " $ prime [ $ rev ] = 0 ; } } } } $ n = 100 ; printEmirp ( $ n ) ; ? >