Skip to content

Instantly share code, notes, and snippets.

@afsardo
Created July 8, 2017 15:54
Show Gist options
  • Save afsardo/aefabd8a3c36222d6e49df7b284f53b1 to your computer and use it in GitHub Desktop.
Save afsardo/aefabd8a3c36222d6e49df7b284f53b1 to your computer and use it in GitHub Desktop.
String always constant number of characters
// Append 0 to the left of the number if needed so the number always has 4 digits
$number = 10;
echo str_pad($number, 4, "0", STR_PAD_LEFT);
// Output: 0010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment