Program to print characters present at prime indexes in a given string | PHP Program to print Characters at Prime index in a given String ; Corner case ; Check from 2 to n - 1 ; Function to print character at prime index ; Loop to check if index prime or not ; Driver Code
< ? php function isPrime ( $ n ) { if ( $ n <= 1 ) return false ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) if ( $ n % $ i == 0 ) return false ; return true ; } function prime_index ( $ input ) { $ n = strlen ( $ input ) ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) if ( isPrime ( $ i ) ) echo $ input [ $ i - 1 ] ; } $ input = " GeeksforGeeks " ; prime_index ( $ input ) ; ? >