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

[php]
<?php
//This is a simple function to return number of digits of an integer.

//function declaration
function count_digit($number)
{
$digit = 0;
do
{
$number /= 10; //$number = $number / 10;
$number = intval($number);
$digit++;
}while($number!=0);
return $digit;
}

//function call
$num = 12312;
$number_of_digits = count_digit($num); //this is call 🙂
echo $number_of_digits;
//prints 5
?>
[/php]

One thought on “PHP snippet : Number of digits of an integer

Leave a Reply

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