First digit in product of an array of numbers | PHP implementation to find first digit of a single number ; Keep dividing by 10 until it is greater than equal to 10 ; Driver Code
< ? php function firstDigit ( $ x ) { while ( $ x >= 10 ) $ x = $ x / 10 ; return floor ( $ x ) ; } echo firstDigit ( 12345 ) , " STRNEWLINE " ; echo firstDigit ( 5432 ) ; ? >