Every time I need this, I start search all over the internet and I simply don’t remember what method to use in PHP. So I’ll post it here:

[code lang=“php”]$hour = sprintf(“%02s”, $key[‘time’][‘hour’]);

$minute = sprintf(“%02s”, $key[‘time’][‘min’]);[/code]

What this does is to change ‘0’ into ‘00’ or ‘2’ into ‘02’, but ‘30’ will still remain as ‘30’. It uses sprintf. I don’t know how you pronounce that it sounds like aspirin to me. The above places a zero in front of a single digit.


Just something not so related. You know the word ‘prepend’ is sort of invented by geeks? It first appear in LISP. In computing, append is typically assumed to be placing something at the end and prepend to be placing something in the beginning. But in English, the word ‘append’ doesn’t really suggest the position of where to add, it basically just means ‘to supplement’.

comments powered by Disqus