Find last index of a character in a string | Returns last index of x if it is present . Else returns - 1. ; String in which char is to be found ; char whose index is to be found
< ? php function findLastIndex ( $ str , $ x ) { $ index = -1 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) if ( $ str [ $ i ] == $ x ) $ index = $ i ; return $ index ; } $ str = " geeksforgeeks " ; $ x = ' e ' ; $ index = findLastIndex ( $ str , $ x ) ; if ( $ index == -1 ) echo ( " Character ▁ not ▁ found " ) ; else echo ( " Last ▁ index ▁ is ▁ " . $ index ) ; ? >