Skip to content

Instantly share code, notes, and snippets.

@scodx
Last active October 11, 2019 20:32
Show Gist options
  • Save scodx/f32528d929ce2d9632d2ebf5ed0963eb to your computer and use it in GitHub Desktop.
Save scodx/f32528d929ce2d9632d2ebf5ed0963eb to your computer and use it in GitHub Desktop.
Adding 0's to a string when is lower than 10 in PHP and JS

PHP

$n = sprintf("%04d", $n)

JS

var n = ('00'+'09').slice(-2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment