judeddokoinu Posted May 16, 2006 Share Posted May 16, 2006 I'm just looking to trim down my code a bit, if possible.I was wondering if PHP itself had a function that does what this one that I wrote does:[code]function leadzero($number){ if ($number < 10) { $new_number = '0' . $number; return $new_number; } else { return $number; }}[/code] Link to comment https://forums.phpfreaks.com/topic/9765-wondering-if-there-is-an-easier-way/ Share on other sites More sharing options...
zq29 Posted May 16, 2006 Share Posted May 16, 2006 You might be able to do it with money_format() - But other than that, I don't think there is one. Link to comment https://forums.phpfreaks.com/topic/9765-wondering-if-there-is-an-easier-way/#findComment-36183 Share on other sites More sharing options...
ryanlwh Posted May 16, 2006 Share Posted May 16, 2006 sprintf or printf. in your case[code] $new = sprintf("%02d",$old); [/code]You can do many different kinds of formatting with sprintf or printf.number_format and money_format are also useful functions to consider. Link to comment https://forums.phpfreaks.com/topic/9765-wondering-if-there-is-an-easier-way/#findComment-36292 Share on other sites More sharing options...
trq Posted May 16, 2006 Share Posted May 16, 2006 You might also try [a href=\"http://php.net/strpad\" target=\"_blank\"]strpad[/a](). Link to comment https://forums.phpfreaks.com/topic/9765-wondering-if-there-is-an-easier-way/#findComment-36316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.