Display values ​​with leading zeros

I want to display digits with leading 0, for the values ​​of one digit, especially for displaying hours and minutes.

How to do it in PHP?

+3
source share
3 answers
str_pad($number, 2, '0', STR_PAD_LEFT);
+7
source

Or take a look at the sprintf () function: http://www.php.net/manual/en/function.sprintf.php

0
source

Using $ val = 1;

print "0".$val ;
-1
source

Source: https://habr.com/ru/post/1736473/


All Articles