I need to cast single figures (1 to 9) to (01 to 09). I can think of a way but its big and ugly and cumbersome. I'm sure there must be some concise way. Any Suggestions
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
There's also str_pad
Solution using str_pad:
Benchmark on php 5.3
Code:
First of all, your description is misleading.
Double
is a floating point data type. You presumably want to pad your digits with leading zeros in a string. The following code does that:For more information, refer to the documentation of
sprintf
.