Programming Tutorials

Function to return number of digits of an integer in PHP

By: Iletras in PHP Tutorials on 2011-04-08  

This is a very simple but useful function to return number of digits of an integer.

//function declaration
function count_digit($number) {
return strlen((string) $number);
}
//function call
$num = 12312;
$number_of_digits = count_digit($num); //this is call :)
echo $number_of_digits;
//prints 5





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)