Function to return number of digits of an integer in PHP

By: Iletras Printer Friendly Format    

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


Ask a Question



Most Viewed Articles (in PHP )

Latest Articles (in PHP)

Comment on this tutorial

Ask a Question

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. Great Thanks
View Tutorial          By: anawaz at 2012-10-05 10:28:20

2. Thanks.It is very helpful
View Tutorial          By: JENI at 2013-03-23 11:01:58

3. thanks. it helped a lot!
View Tutorial          By: lateforbus at 2013-04-25 03:35:24

4. if the number is for exemple 00025478 it return a
View Tutorial          By: ahmed at 2015-02-11 12:02:45

5. enuciluluzi
View Tutorial          By: enuciluluzi at 2017-01-08 04:46:18

6. ikeboite
View Tutorial          By: ikeboite at 2017-01-08 05:01:48

7. dcelneqezu
View Tutorial          By: dcelneqezu at 2017-01-08 05:07:51

8. Lorenton
View Tutorial          By: Lorenton at 2017-06-23 10:25:29

9. epoehoqo
View Tutorial          By: epoehoqo at 2017-09-05 14:15:19

10. ebootomuxo
View Tutorial          By: ebootomuxo at 2017-09-05 15:06:16

11. ekukela
View Tutorial          By: ekukela at 2017-09-06 14:33:01