zeroise( int $number, int $threshold ): string
- Since
- 0.71
- Source
wp-includes/formatting.php:2791
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.
Compatibility
- WordPress
- since 0.71
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$numberint- Number to append zeros to if not greater than threshold.
$thresholdint- Digit places number needs to be to not have zeros added.
Return value
string- Adds leading zeros to number if needed.
Performance profile
How much work a call to zeroise() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 9
- Plugin surface
- None
- Called by
- 11
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 9.
Nothing here hands control to plugin code.
11 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost zeroise() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 9 | 9 | 0 | |
| 8.5 | 9 | 9 | 0 | |
| 8.4 | 9 | 9 | 0 | |
| 8.3 | 9 | 9 | 0 | |
| 8.2 | 9 | 9 | 0 | |
| 8.1 | 9 | 9 | 0 | 83 fewer instructions than PHP 7.4 |
| 7.4 | 92 | 22–53 | 4 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Used by · 11
- WP_List_Table::months_dropdown()Displays a dropdown for filtering items in the list table by month.
- WP_Locale::get_month()Retrieves the full translated month by month number.
- WP_Locale::get_month_genitive()Retrieves translated version of month genitive string.
- antispambot()Converts email addresses characters to HTML entities to block spam bots.
- export_date_options()Creates the date options fields for exporting a given post type.
- get_calendar()Displays calendar with days that have posts as links.
- get_day_link()Retrieves the permalink for the day archives with year and month.
- get_month_link()Retrieves the permalink for the month archives with year.
- media_upload_library_form()Outputs the legacy media upload form for the media library.
- touch_time()Prints out HTML form date elements for editing post or comment publish date.
- wp_title()Displays or retrieves page title for all areas of blog.
Source code
function zeroise( $number, $threshold ) { return sprintf( '%0' . $threshold . 's', $number );}Changelog
Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.