PHP snippet : Number of digits of an integer

This is a basic PHP program that returns the number of digits of an integer.

//This is a simple function to return number of digits of an integer.

//function declaration
function count_digit($number)
$digit = 0;
$number /= 10; //$number = $number / 10;
$number = intval($number);
return $digit;

//function call
$num = 12312;
$number_of_digits = count_digit($num); //this is call 🙂
echo $number_of_digits;
//prints 5

Mohit Kumar

A simple person who likes to share his thoughts on this blog. Know more about me

You may also like...

1 Response

  1. Alan says:

    or what about strlen( (string) $num );

Leave a Reply

Your email address will not be published. Required fields are marked *