Reputation: 1645
I want format number as style '00000' ex:
$a=1 => $a2="00001"
$b=23 => $b2="00023"
How format number in php?
Upvotes: 0
Views: 96
Reputation: 39550
$formattedValue = sprintf('%05s', $value);
0
is the character to pad 5
times. s
specifies that it's a string.Upvotes: 1
Reputation: 669
You should use str_pad : https://www.php.net/manual/en/function.str-pad.php
$formattedValue = str_pad($value, 6, "0", STR_PAD_LEFT);
Upvotes: 3