This pads to the right of the number, and pads with spaces not zeros. $padded = str_pad($number, $width, 0, STR_PAD_LEFT);
– Tom HaighSep 18 '09 at 10:09
Yeah, ommission on my part. Corrected. But I would retain some semblance of type safety by providing appropriate types (even if conversion is automatic).
– JoeSep 18 '09 at 10:32
2
Depending on the scenario, I'd say this is usually the better solution. Additionally, it is not currently necessary to explicitly cast to `string` unless you use a numeric literal in `str_pad`. A variable of a numeric type will be implicitly cast.
– Jack HenahanMar 16 '14 at 22:28