text: Find repeated character present first in a string | PHP program to find the first character that is repeated ; this is O ( N ^ 2 ) method ; Driver code
code: < ? php function findRepeatFirstN2 ( $ s ) { $ p = -1 ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) { for ( $ j = ( $ i + 1 ) ; $ j < strlen ( $ s ) ; $ j ++ ) { if ( $ s [ $ i ] == $ s [ $ j ] ) { $ p = $ i ; break ; } } if ( $ p != -1 ) break ; } return $ p ; } $ str = " geeksforgeeks " ; $ pos = findRepeatFirstN2 ( $ str ) ; if ( $ pos == -1 ) echo ( " Not ▁ found " ) ; else echo ( $ str [ $ pos ] ) ; ? >