Find first and last digits of a number | Find the first digit ; Find total number of digits - 1 ; Find first digit ; Return first digit ; Find the last digit ; return the last digit ; Driver Code
< ? php function firstDigit ( $ n ) { $ digits = ( int ) log10 ( $ n ) ; $ n = ( int ) ( $ n / pow ( 10 , $ digits ) ) ; return $ n ; } function lastDigit ( $ n ) { return ( $ n % 10 ) ; } $ n = 98562 ; echo firstDigit ( $ n ) , " " , lastDigit ( $ n ) , " " ; ? >