text: Minimum rotations required to get the same string | Returns count of rotations to get the same string back . ; tmp is the concatenated string . ; substring from i index of original string size . ; if substring matches with original string then we will come out of the loop . ; Driver code
code: < ? php function findRotations ( $ str ) { $ tmp = ( $ str + $ str ) ; $ n = strlen ( $ str ) ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ substring = $ tmp . substr ( $ i , strlen ( $ str ) ) ; if ( $ str == $ substring ) return $ i ; } return $ n ; } $ str = " abc " ; echo findRotations ( $ str ) , " STRNEWLINE " ; ? >