How to Add / Remove leading zeros before number in PHP ?
|What is a simple way how to add / remove leading zeros before number in PHP ?|
There are multiple methods available how to add or remove leading zeros before number.
To add leading zero before number, you can use sprintf(). The following function will add leading zero before a single digit number:
$value = sprintf('%02d', $number);
To remove leading zeros before number, you can use ltrim() or (int):
$value = ltrim($number, "0");
$value = (int)$number;
|How to calculate inverse currency exchange rate ?|
|How to add side by side rows in excel pivot table ?|
|Remove or hide bottom navigation bar with buttons on Android|
|How to change QWERTZ keyboard to QWERTY in Windows 10 ?|
|Invitation emails disappear after meeting is accepted in Outlook|
|How to see who is invited to a meeting - attendees in Outlook|
|How to calculate how many Man Days are 3 Man Hours ?|