Check if the given string is K | Function that return true if sub - of length $k starting at index $i is also a prefix of the string ; $k length sub - cannot start at index $i ; Character mismatch between the prefix and the sub - starting at index $i ; Function that returns true if $str is K - periodic ; Check whether all the sub - strings $str [ 0 , $k - 1 ] , $str [ $k , 2 k - 1 ] ... are equal to the $k length prefix of the ; Driver code
< ? php function isPrefix ( $ str , $ len , $ i , $ k ) { if ( $ i + $ k > $ len ) return false ; for ( $ j = 0 ; $ j < $ k ; $ j ++ ) { if ( $ str [ $ i ] != $ str [ $ j ] ) return false ; $ i ++ ; } return true ; } function isKPeriodic ( $ str , $ len , $ k ) { for ( $ i = $ k ; $ i < $ len ; $ i += $ k ) if ( ! isPrefix ( $ str , $ len , $ i , $ k ) ) return false ; return true ; } $ str = " geeksgeeks " ; $ len = strlen ( $ str ) ; $ k = 5 ; if ( isKPeriodic ( $ str , $ len , $ k ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >