Print last character of each word in a string | Function to print the last character of each word in the given string ; Now , last word is also followed by a space ; If current character is a space ; Then previous character must be the last character of some word ; Driver code
< ? php function printLastChar ( $ str ) { $ str = $ str . " ▁ " ; for ( $ i = 1 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( ! strcmp ( $ str [ $ i ] , ' ▁ ' ) ) echo ( $ str [ $ i - 1 ] . " ▁ " ) ; } } $ str = " Geeks ▁ for ▁ Geeks " ; printLastChar ( $ str ) ; ? >