Skip to Content
Menu

singular_plural()

A convenient PHP function for returning a singular or plural label string based on the value.

PHP February 26, 2023

Usage

PHP
singular_plural($value, $singular, $plural)

Parameters

$value
(Required) (Integer or Float) The value to determine the label for
Default: None

$singular
(Required) (String) The singular label
Default: None

$plural
(Optional) (String) The plural label
Default: Adds an "s" to the singular label

Parameter Notes

If the plural form of the singular label is the same but with an “s” (like “book” and “books”), you do not need to pass the plural parameter.

Request or provide clarification »

Examples

When the plural simply adds an "s", no need for the third parameter.

PHP
echo singular_plural($number, 'hour');

When the plural is spelled differently, the third parameter is needed.

PHP
echo singular_plural($number, 'story', 'stories');
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    This function was not found in /libs/Utilities.php. Please report this error.

    No Hooks

    This function does not have any filters or actions available. Request one?

    Override

    This function can not be short-circuited with an override filter. Request one?