For example, I have this format:
$s_number = "12";
And for this input, I need 0012
as the output:
Another example:
Input $s_number = "3";
Output: 0003
Every time I need 4 digits I would like this to happen.
It won't be a number (but a string), but you can do that using str_pad. In your examples:
$s_number = str_pad( "12", 4, "0", STR_PAD_LEFT );
$s_number = str_pad( "3", 4, "0", STR_PAD_LEFT );
Use str_pad()
for that:
echo str_pad($number, 4, '0', STR_PAD_LEFT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With