N 'th palindrome of K digits | Utility function to reverse the number n ; Boolean Function to check for palindromic number ; Function for finding nth palindrome of k digits ; Get the smallest k digit number ; check the number is palindrom or not ; if n 'th palindrome found  break the loop ; Increment number for checking next palindrome ; Driver code
< ? php function reverseNum ( $ n ) { $ rem ; $ rev = 0 ; while ( $ n ) { $ rem = $ n % 10 ; $ rev = ( $ rev * 10 ) + $ rem ; $ n = ( int ) ( $ n / 10 ) ; } return $ rev ; } function isPalindrom ( $ num ) { return $ num == reverseNum ( $ num ) ; } function nthPalindrome ( $ n , $ k ) { $ num = pow ( 10 , $ k - 1 ) ; while ( true ) { if ( isPalindrom ( $ num ) ) -- $ n ; if ( ! $ n ) break ; ++ $ num ; } return $ num ; } $ n = 6 ; $ k = 5 ; echo $ n , " th ▁ palindrome ▁ of ▁ " , $ k , " ▁ digit ▁ = ▁ " , nthPalindrome ( $ n , $ k ) , " STRNEWLINE " ; $ n = 10 ; $ k = 6 ; echo $ n , " th ▁ palindrome ▁ of ▁ " , $ k , " ▁ digit ▁ = ▁ " , nthPalindrome ( $ n , $ k ) , " STRNEWLINE " ; ? >