$raw = 1; $formatted = sprintf("%02d", $raw); echo $formatted; //outputs 01
You need to create an account or log in to post comments to this site.
12374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
$raw = 1; $formatted = sprintf("%02d", $raw); echo $formatted; //outputs 01
You need to create an account or log in to post comments to this site.
Longer, yes, but you don't have to remember funky stuff like %02d. Besides, I'd never remember what that line of code did later on when I was looking back at it...