Find next palindrome prime | PHP program to find next palindromic prime for a given number . ; if ( 8 <= N <= 11 ) return 11 ; generate odd length palindrome number which will cover given constraint . ; if y >= N and it is a prime number then return it . ; Driver code
< ? php function isPrime ( $ num ) { if ( $ num < 2 $ num % 2 == 0 ) return $ num == 2 ; for ( $ i = 3 ; $ i * $ i <= $ num ; $ i += 2 ) if ( $ num % $ i == 0 ) return false ; return true ; } function primePalindrome ( $ N ) { if ( 8 <= $ N && $ N <= 11 ) return 11 ; for ( $ x = 1 ; $ x < 100000 ; ++ $ x ) { $ s = strval ( $ x ) ; $ r = strrev ( $ s ) ; $ y = intval ( $ s . substr ( $ r , 1 ) ) ; if ( $ y >= $ N && isPrime ( $ y ) == true ) return $ y ; } return -1 ; } print ( primePalindrome ( 112 ) ) ; ? >