Tutorial Force Leading Zero

by in , 0

<?php
  function forceLeadingZero($int) {
    return (int)sprintf('%02d',$int);
  }
?>

Forces leading zero to integers.

was | now

1 | 01
2 | 02
3 | 03

10 | 10
100 | 100
99 | 99

Reference URL

Leave a Reply