Skip to main content
Home / Code Snippets / PHP / Zero Padded Numbers

Zero Padded Numbers

function getZeroPaddedNumber($value, $padding) {
       return str_pad($value, $padding, "0", STR_PAD_LEFT);
}

Usage

echo getZeroPaddedNumber(123, 4);
// outputs "0123"
icon-link icon-logo-star icon-search icon-star