wordpress / latest / functions / zeroise.html

zeroise( int $number, int $threshold ): string

Add leading zeros when necessary.

Description

If you set the threshold to ‘4’ and the number is ’10’, then you will get back ‘0010’. If you set the threshold to ‘4’ and the number is ‘5000’, then you will get back ‘5000’.

Uses sprintf to append the amount of zeros based on the $threshold parameter and the size of the number. If the number is large enough, then no zeros will be appended.

Parameters

$number int Required
Number to append zeros to if not greater than threshold.
$threshold int Required
Digit places number needs to be to not have zeros added.

Return

string Adds leading zeros to number if needed.

Source

File: wp-includes/formatting.php. View all references

function zeroise( $number, $threshold ) {
	return sprintf( '%0' . $threshold . 's', $number );
}

Used By

Used By Description

Changelog

Version Description
0.71 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/zeroise