Predicates
Callbacks
- is_and
is_and(string | callable ...$predicate): callable
The returned callable returns true if and only if all predicates return true literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,'seven']; array_filter($values, is_and('is_scalar', 'is_positive', 'is_even')); // [2,4,6]
is_and('is_positive', 'is_truthy', is_not('is_even'))('1'); //true
is_and('is_positive', fn (`$i) => `$i != 2, is_not('is_odd'))(4); //true
- is_nand
is_nand(string | callable ...$predicate): callable
The returned callable returns true if and only if at least one predicate does not return true literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,'seven']; array_filter($values, is_nand('is_positive', 'is_odd')); // [0,-2,2,4,6,'seven']
is_nand('is_positive', 'is_falsy')('1'); //true
is_nand('is_positive', fn (`$i) => `$i == 2)(4); //true
- is_nn_and
is_nn_and(string | callable ...$predicate): callable
— Likeis_and
, ignoring null values by defaultThe returned callable returns true if and only if all predicates return true literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,null,'seven']; array_filter($values, is_nn_and('is_scalar', 'is_positive', 'is_even')); // [2,4,6]
- is_nor
is_nor(string | callable ...$predicate): callable
The returned callable returns true if and only if all the predicates return false literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,'seven','y','n','yes','NO']; array_filter($values, is_nor('is_positive', 'is_odd', 'is_truthy')); // [0,-2,seven,n,ON]
is_nor('is_positive', 'is_falsy')('1'); //false
- is_not
is_not(string | callable $predicate): callable
The returned callable returns true if and only if the predicate returns false literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,'seven','y','n','yes','NO']; array_filter($values, is_not('is_positive')); // [0,2,seven,y,n,yes,NO]
is_not('is_positive', 'is_falsy')('1'); //false
- is_or
is_or(string | callable ...$predicate): callable
The returned callable returns true if any of the predicates return true literal
-
Examples
$values = [0,1,-2,2,3,4,5,6,'seven','y','n','yes','NO']; array_filter($values, is_or('is_positive', 'is_odd', 'is_truthy')); // [1,2,3,4,5,6,y,yes]
is_or('is_positive', 'is_falsy')('1'); //true
- is_xnor
is_xnor(string | callable $apred, string | callable $bpred): callable
The returned callable returns true if and only if both of the predicates return the same value
P Q XNOR T T T T F F F T F F F T -
Examples
$values = [0,1,-2,2,3,4,5,6,'seven','y','n','yes','NO']; array_filter($values, is_xnor('is_positive', 'is_truthy')); // [0,1,-2,seven,n,NO]
- is_xor
is_xor(string | callable $apred, string | callable $bpred): callable
The returned callable returns true if and only if any of the predicates return true literal, but not both
P Q XOR T T F T F T F T T F F F -
Examples
$values = [0,1,-2,2,3,4,5,6,'seven','y','n','yes','NO']; array_filter($values, is_xor('is_positive', 'is_truthy')); // [2,3,4,5,6,y,yes]
General
- contains
contains(mixed $needle, mixed $haystack): bool
This predicate returns true if $haystack contains $needle - case sensitive
The following conditions satisfy 'contains':
- $haystack is array then
in_array($needle, $haystack)
- $haystack is object then
in_array($needle, array_keys(get_object_vars($haystack)))
- $needle is string and $haystack is string then `str_contains($haystack, $needle)``
- $needle is numeric and $haystack is numeric then
str_contains(strval($haystack), strval($needle))
- $haystack is array then
-
Examples
$values = ['a', 'b', 'c']; var_dump(contains('b', $values)); //true var_dump(contains('B', $values)); //false
$obj = new stdClass; $obj->FOO = "foo"; $obj->BaR = "bar"; var_dump(contains('BaR', $obj)); //true var_dump(contains('foo', $obj)); //false
$value = "Hello World"; var_dump(contains("llo", $value)); //true var_dump(contains("world", $value)); //false
$value = "00123.00"; var_dump(contains(123, $value)); //true
- ends_with
ends_with(mixed $needle, $mixed $haystack): bool
This predicate returns true if $haystack ends with $needle - case sensitive
The following conditions satisfy 'ends_with'
- $haystack is array then last element in array == $needle
- $haystack is string or numeric then
str_ends_with($haystack, $needle)
-
Examples
$value = 'aoeuhtns1234'; var_dump(ends_with('1234', $value)); //true
$value = ['aoeuhtns1234']; var_dump(ends_with('1234', $value)); //false var_dump(ends_with('aoeuhtns1234', $value)); //true
var_dump(ends_with(1234, 98761234)); //true
- icontains
icontains(mixed $needle, mixed $haystack): bool
— Likecontains()
but case insensitive lookups where appropriateThis predicate returns true if $haystack contains $needle - case insensitive
The following conditions satisfy 'contains':
- $haystack is array then
in_array($needle, $haystack)
- $haystack is object then
in_array($needle, array_keys(get_object_vars($haystack)))
- $needle is string and $haystack is string then
str_contains($haystack, $needle)
- $needle is numeric and $haystack is numeric then
str_contains(strval($haystack), strval($needle))
- $haystack is array then
-
Examples
$values = ['a', 'b', 'c']; var_dump(icontains('b', $values)); //true var_dump(icontains('B', $values)); //true
$obj = new stdClass; $obj->FOO = "foo"; $obj->BaR = "bar"; var_dump(icontains('BaR', $obj)); //true var_dump(icontains('foo', $obj)); //true
$value = "Hello World"; var_dump(icontains("llo", $value)); //true var_dump(icontains("world", $value)); //true
$value = "00123.00"; var_dump(icontains(123, $value)); //true
- iends_with
iends_with(mixed $needle, $mixed $haystack): bool
— Likeends_with()
but case insensitive look upsThis predicate returns true if $haystack ends with $needle - case insensitive
The following conditions satisfy 'ends_with'
- $haystack is array then last element in array == $needle
- $haystack is string or numeric then
str_ends_with($haystack, $needle)
-
Examples
$value = 'aoeuhtns1234'; var_dump(istarts_with('aoeu', $value)); //true
$value = ['aoeuhtns1234']; var_dump(istarts_with('aoeu', $value)); //false var_dump(istarts_with('aoeuhtns1234', $value)); //true
var_dump(istarts_with(9876, 98761234)); //true
- is_empty
is_empty(mixed $value): bool
This predicate returns true if $value is not empty
The following conditions statisfy 'empty':
- $value is
null
- $value is string and
strlen($value) == 0
(trim applied) - $value is array and array is empty
- $value is object and
get_object_vars($value)
is empty - $value is numeric and $value == 0
- $value is
-
Examples
var_dump(is_empty(null)); //true var_dump(is_empty('')); //true var_dump(is_empty(' ')); //true var_dump(is_empty(Array())); //true var_dump(is_empty(new stdClass)); //true var_dump(is_empty(new class {})); //true var_dump(is_empty('000')); //true var_dump(is_empty(0)); //true
- is_false
is_false(mixed $value): bool
This predicate returns true if $value is false literal
-
Examples
var_dump(is_false('0')); //false var_dump(is_false(false)); //true
- is_falsy
is_falsy(mixed $value): bool
This predicate returns true if $value is 'falsy', or false-like
-
Examples
var_dump(is_falsy('0')); //true var_dump(is_falsy('1')); //false var_dump(is_falsy(false)); //true var_dump(is_falsy('FALSE')); //true var_dump(is_falsy('f')); //true var_dump(is_falsy('n')); //true var_dump(is_falsy('no')); //true var_dump(is_falsy('off')); //true var_dump(is_falsy(' false')); //true
- is_non_null
is_non_null(mixed $value): bool
This predicate returns true if $value is not null
-
Examples
var_dump(is_non_null(null)); //false var_dump(is_non_null(new stdClass)); //true var_dump(is_non_null(0)); //true var_dump(is_non_null(false)); //true
- is_not_false
is_not_false(mixed $value): bool
This predicate returns true if $value is not false literal
-
Examples
var_dump(is_not_false(false)); //false var_dump(is_not_false(true)); //true var_dump(is_not_false(12350987)); //true var_dump(is_not_false(new stdClass)); //true var_dump(is_not_false("Hello World")); //true
- is_not_true
is_not_true(mixed $value): bool
This predicate returns true if $value is not true literal
-
Examples
var_dump(is_not_true(false)); //true var_dump(is_not_true(true)); //false var_dump(is_not_true(12350987)); //true var_dump(is_not_true(new stdClass)); //true var_dump(is_not_true("Hello World")); //true
- is_palidrome
is_palidrome(string | int | null $value): bool
This predicate returns true if $value equals the reverse of $value
-
Examples
var_dump(is_palidrome(123454321)); //true var_dump(is_palidrome('abba')); //true var_dump(is_palidrome('racecar')); //true
- is_true
is_true(mixed $value): bool
This predicate returns true if $value is true literal
-
Examples
var_dump(is_true(1)); //false var_dump(is_true(false)); //false var_dump(is_true(true)); //false
- is_truthy
is_truthy(mixed $value): bool
This predicate returns true if $value is 'truthy', or true-like
-
Examples
var_dump(is_truthy('0')); //false var_dump(is_truthy('1')); //true var_dump(is_truthy(true)); //true var_dump(is_truthy('TRUE')); //true var_dump(is_truthy('t')); //true var_dump(is_truthy('y')); //true var_dump(is_truthy('yes')); //true var_dump(is_truthy('on')); //true var_dump(is_truthy(' true')); //true
- istarts_with
istarts_with(mixed $needle, $mixed $haystack): bool
— Likestarts_with()
but case insensitive look upsThis predicate returns true if $haystack starts with $needle - case insensitive
The following conditions satisfy 'starts_with'
- $haystack is array then first element in array == $needle
- $haystack is string or numeric then
str_starts_with($haystack, $needle)
-
Examples
$value = 'aoeuhtns1234'; var_dump(iends_with('1234', $value)); //true
$value = ['aoeuhtns1234']; var_dump(iends_with('1234', $value)); //false var_dump(iends_with('aoeuhtns1234', $value)); //true
var_dump(iends_with(1234, 98761234)); //true
- starts_with
starts_with(mixed $needle, $mixed $haystack): bool
This predicate returns true if $haystack starts with $needle - case sensitive
The following conditions satisfy 'starts_with'
- $haystack is array then first element in array == $needle
- $haystack is string or numeric then
str_starts_with($haystack, $needle)
-
Examples
$value = 'aoeuhtns1234'; var_dump(starts_with('AOEU', $value)); //false var_dump(starts_with('aoeu', $value)); //true
$value = ['aoeuhtns1234']; var_dump(starts_with('aoeu', $value)); //false var_dump(starts_with('aoeuhtns1234', $value)); //true
var_dump(starts_with(9876, 98761234)); //true
Platform
- is_bsd
is_bsd(): bool
This predicate returns true if the
PHP_OS_FAMILY
constant value is BSD- is_darwin
is_darwin(): bool
This predicate returns true if the
PHP_OS_FAMILY
constant value is Darwin- is_linux
is_linux(): bool
This predicate returns true if the
PHP_OS_FAMILY
constant value is Linux- is_solaris
is_solaris(): bool
This predicate returns true if the
PHP_OS_FAMILY
constant value is Solaris- is_windows
is_windows(): bool
This predicate returns true if the
PHP_OS_FAMILY
constant value is Windows
PHP
- is_current_version
is_current_version(?string $value): bool
This predicate returns true if $value falls between the beginning of the current minor version and the next minor version
-
Examples
var_dump(is_current_version("8.1.0")); //true var_dump(is_current_version("8.1.99")); //true var_dump(is_current_version("8.2.0")); //false
- is_future_version
is_future_version(?string $value): bool
This predicate returns true if $value is greater than the
PHP_VERSION
constant value-
Examples
var_dump(is_future_version("8.1.0")); //false var_dump(is_future_version("8.1.9")); //true var_dump(is_future_version("9")); //true var_dump(is_future_version("9.0")); //true
- is_past_version
is_past_version(?string $value): bool
This predicate returns if $value is less than the
PHP_VERSION
constant value-
Examples
var_dump(is_past_version("8.1.0")); //true var_dump(is_past_version("8.1.8")); //false var_dump(is_past_version("8.1.7")); //true var_dump(is_past_version("8")); //true
- is_php6
is_php6(?string $value = null): bool
This predicate returns true if $value is greater than or equal to 6 and less than 7
If $value is null
PHP_MAJOR_VERSION
will be used implicitly-
Examples
var_dump(is_php6("6")); //true var_dump(is_php6("6.9.9")); //true var_dump(is_php6("7")); //false var_dump(is_php6()); //false
- is_php7
is_php7(?string $value = null): bool
This predicate returns true if $value is greater than or equal to 7 and less than 8
If $value is null
PHP_MAJOR_VERSION
will be used implicitly-
Examples
var_dump(is_php7("7")); //true var_dump(is_php7("7.9.9")); //true var_dump(is_php7("8")); //false var_dump(is_php7()); //false
- is_php8
is_php8(?string $value = null): bool
This predicate returns true if $value is greater than or equal to 8 and less than 9
If $value is null
PHP_MAJOR_VERSION
will be used implicitly-
Examples
var_dump(is_php8("8")); //true var_dump(is_php8("8.9.9")); //true var_dump(is_php8("8")); //true var_dump(is_php8()); //true
- is_version_number
is_version_number(?string $value): bool
This predicate returns true if $value matches a PHP version number
The following patterns satisfy a PHP version:
#
#.#
#.#.#
-
Examples
var_dump(is_version_number('5')); //true var_dump(is_version_number('5.')); //false var_dump(is_version_number('5.5')); //true var_dump(is_version_number('5.5.')); //false var_dump(is_version_number('5.5.5')); //true var_dump(is_version_number('5.5.5.')); //false var_dump(is_version_number('10.0.0')); //true
Server
- is_http_connect
is_http_connect(?string $value = null): bool
This predicate returns if $value is an HTTP CONNECT request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_connect($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'connect', 'GET']; var_dump(array_filter($values, 'is_http_connect')); // [connect]
var_dump(is_http_connect()); //true
- is_http_delete
is_http_delete(?string $value = null): bool
This predicate returns if $value is an HTTP DELETE request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_delete($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'DELETE', 'GET', 'del']; var_dump(array_filter($values, 'is_http_delete')); // [DELETE]
var_dump(is_http_delete()); //true
- is_http_get
is_http_get(?string $value = null): bool
This predicate returns if $value is an HTTP GET request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_get($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'DELETE', 'GET', 'del']; var_dump(array_filter($values, 'is_http_get')); // [GET]
var_dump(is_http_get()); //true
- is_http_head
is_http_head(?string $value = null): bool
This predicate returns if $value is an HTTP HEAD request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_head($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'head', 'GET', 'del']; var_dump(array_filter($values, 'is_http_head')); // [head]
var_dump(is_http_head()); //true
- is_http_method
is_http_method(?string $value): bool
This predicate returns true if $value is a valid HTTP request method
-
Examples
$user_input = 'post'; var_dump(is_http_method($user_input)); //true
$values = ['abc', 123, 'post', 'conn', 'head', 'GET', 'del']; var_dump(array_filter($values, 'is_http_method')); // [post, head, GET]
- is_http_options
is_http_options(?string $value = null): bool
This predicate returns if $value is an HTTP OPTIONS request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_options($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'options', 'GET', 'del']; var_dump(array_filter($values, 'is_http_options')); // [options]
var_dump(is_http_options()); //true
- is_http_patch
is_http_patch(?string $value = null): bool
This predicate returns if $value is an HTTP PATCH request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_patch($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'patch', 'GET', 'del']; var_dump(array_filter($values, 'is_http_patch')); // [patch]
var_dump(is_http_patch()); //true
- is_http_post
is_http_post(?string $value = null): bool
This predicate returns if $value is an HTTP POST request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'put'; var_dump(is_http_post($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'options', 'GET', 'del']; var_dump(array_filter($values, 'is_http_post')); // [post]
var_dump(is_http_post()); //true
- is_http_put
is_http_put(?string $value = null): bool
This predicate returns if $value is an HTTP PUT request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_put($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'options', 'GET', 'PUT']; var_dump(array_filter($values, 'is_http_put')); // [PUT]
var_dump(is_http_put()); //true
- is_http_trace
is_http_trace(?string $value = null): bool
This predicate returns if $value is an HTTP TRACE request
If $value is null the request method in the global $_SERVER variable will be used implicitly
-
Examples
$user_input = 'post'; var_dump(is_http_trace($user_input)); //false
$values = ['abc', 123, 'post', 'conn', 'options', 'GET', 'trace']; var_dump(array_filter($values, 'is_http_trace')); // [trace]
var_dump(is_http_trace()); //true
Numbers
- is_actual_byte
is_actual_byte(string | int | float | null $value): bool
This predicate returns true if
C_BYTE_MIN >= $value <= C_BYTE_MAX
and is not an e-notated number/numeric string and is not a float, including.00
floats-
Examples
var_dump(is_actual_byte(.5)); //false var_dump(is_actual_byte('abc')); //false var_dump(is_actual_byte('125')); //true var_dump(is_actual_byte(1e+10)); //false var_dump(is_actual_byte('1e+10')); //false var_dump(is_actual_byte(127)); //true var_dump(is_actual_byte(128)); //false var_dump(is_actual_byte(-128)); //true
- is_actual_float
is_actual_float(string | int | float | null $value): bool
This predicate returns true if $value has decimals and is not an e-notated numeric string
-
Examples
var_dump(is_actual_float(.5)); //true var_dump(is_actual_float('-.5')); //true var_dump(is_actual_float('abc')); //false var_dump(is_actual_float('125.')); //true var_dump(is_actual_float(125.)); //true var_dump(is_actual_float(1e+10)); //true var_dump(is_actual_float('1e+10')); //false var_dump(is_actual_float(PHP_INT_MAX)); //false var_dump(is_actual_float(PHP_INT_MAX + 1)); //true
- is_actual_int
is_actual_int(string | int | float | null $value): bool
This predicate returns true if
C_INT_MIN >= $value <= C_INT_MAX
and is not an e-notated number/numeric string and is not a float, including.00
floats-
Examples
var_dump(is_actual_int(.5)); //false var_dump(is_actual_int('abc')); //false var_dump(is_actual_int('125.')); //false var_dump(is_actual_int('-.5')); //false var_dump(is_actual_int(125.)); //false var_dump(is_actual_int(1e+10)); //false var_dump(is_actual_int('1e+10')); //false var_dump(is_actual_int(PHP_INT_MAX)); //false var_dump(is_actual_int(2_147_483_647)); //true
- is_actual_long
is_actual_long(string | int | float | null $value): bool
This predicate returns true if
C_LONG_MIN >= $value <= C_LONG_MAX
and is not an e-notated number/numeric string and is not a float-
Examples
var_dump(is_actual_long(.5)); //false var_dump(is_actual_long('abc')); //false var_dump(is_actual_long('125.')); //false var_dump(is_actual_long('-.5')); //false var_dump(is_actual_long(125.)); //false var_dump(is_actual_long(1e+10)); //false var_dump(is_actual_long('1e+10')); //false var_dump(is_actual_long(PHP_INT_MAX)); //true var_dump(is_actual_long(PHP_INT_MAX + 1)); //false var_dump(is_actual_long(2_147_483_647)); //true
- is_actual_short
is_actual_short(string | int | float | null $value): bool
This predicate returns if
C_SHORT_MIN >= $value <= C_SHORT_MAX
and is not an e-notated number/numeric string and is not a float, including.00
floats-
Examples
var_dump(is_actual_short(.5)); //false var_dump(is_actual_short('abc')); //false var_dump(is_actual_short('125.')); //false var_dump(is_actual_short('-.5')); //false var_dump(is_actual_short(125.)); //false var_dump(is_actual_short(1e+10)); //false var_dump(is_actual_short('1e+10')); //false var_dump(is_actual_short(PHP_INT_MAX)); //false var_dump(is_actual_short(PHP_INT_MAX + 1)); //false var_dump(is_actual_short(2_147_483_647)); //false var_dump(is_actual_short(-32768)); //true var_dump(is_actual_short(32767)); //true var_dump(is_actual_short(32768)); //false
- is_armstrong
is_armstrong(string | int | float | null $value): bool
This predicate returns true if $value is a base 10 armstrong number
An armstrong number
n
is a natural number that is the sum of its own digits each raised to the power of the number of digits:For example, 153 is a natural number because:
- It is a natural number
- There are 3 digits (di) = sum(pow(di, 3)) = n
1 5 3 (1*1*1) + (5*5*5) + (3*3*3) = 153
-
Examples
var_dump(is_armstrong(-1)); //false var_dump(is_armstrong(1)); //true var_dump(is_armstrong(9)); //true var_dump(is_armstrong(153)); //true var_dump(is_armstrong(370)); //true var_dump(is_armstrong(371)); //true
- is_between
is_between(string | int | float | null $value, string | int | float | null $a, string | int | float | null $b): bool
This predicate returns true if $value is between two numbers (exclusive)
-
Examples
var_dump(is_between(null, 0, 10)); //false var_dump(is_between(0, 0, 10)); //false var_dump(is_between(10, 0, 10)); //false var_dump(is_between(5, 0, 10)); //true var_dump(is_between(0.5, 0, 10)); //true var_dump(is_between('5', 0, 10)); //true var_dump(is_between('.5', 0, 10)); //true
- is_byte
is_byte(string | int | float | null $value): bool
— Alias for is_actual_byte()- is_dudeney
is_dudeney(string | int | float | null $value): bool
This predicate returns true if $value is a base 10 dudeney number
A dudeney number
n
is a natural number where the sum of its digits is equal to cube root ofn
For example, 512 is a dudeney number because:
- It is a natural number
- It's cube root is 8
- The sum of it's digits = 5 + 1 + 2 = 8
- is_even
is_even(string | int | float | null $value): bool
This predicate returns true if $value is an even number
-
Examples
var_dump(is_even(0)); //true var_dump(is_even('1')); //false var_dump(is_even(-100)); //true var_dump(is_even(4)); //true var_dump(is_even(4.00)); //true
- is_factorion
is_factorion(string | int | float | null $value): bool
This predicate returns true if $value is a base 10 factorion number
A factorion number
n
is a positive number that is equal to the sum of the factorials of it's digitsFor example, 145 is a factorion number because:
- It is a positive number
- Each digit's factorial sums to
n
1! + 4! + 5! 1( 1 ) + 4( 3 x 2 x 1 ) + 5( 4 x 3 x 2 x 1 ) 1( 1 ) + 4( 6 ) + 5( 24 ) 1 + 24 + 120
- is_happy_number
is_happy_number(string | int | float | null $value): bool
This predicate returns true if $value is a base 10 happy number
A happy number
n
is a natural number which eventually reaches 1 when replaced by the sum of each digits squaresFor example, 23 is a happy number because:
- It is a natural number
- The sum of each digit's square eventually reduces to
1
2² + 3² (2 * 2) + (3 * 3) 4 + 9 = 13 1² + 3² (1 * 1) + ( 3 * 3 ) 1 + 9 = 10 1² + 0² (1 * 1) + (0 * 0) 1 + 0
- is_harshad
is_harshad(string | int | float | null $value): bool
This predicate returns true if $value is a base 10 harshad number
A harshad number
n
is a natural number that is divisible by the sum of its digitsFor example, 21 is a harshad number because:
- It is a natural number
- The sum of it's digits is 3
- 21 is divisible by 3
-
Examples
var_dump(is_harshad(0)); //false var_dump(is_harshad('1')); //true var_dump(is_harshad(-100)); //false var_dump(is_harshad(50)); //true var_dump(is_harshad(54)); //true var_dump(is_harshad(100.00)); //false var_dump(is_harshad(100)); //true
- is_in_range
is_in_range(string | int | float | null $value, string | int | float | null $a, string | int | float | null $b): bool
This predicate returns true if $value is between two numbers (inclusive)
-
Examples
var_dump(is_in_range(null, 0, 10)); //false var_dump(is_in_range(0, 0, 10)); //true var_dump(is_in_range(10, 0, 10)); //true var_dump(is_in_range(5, 0, 10)); //true var_dump(is_in_range(0.5, 0, 10)); //true var_dump(is_in_range('5', 0, 10)); //true var_dump(is_in_range('.5', 0, 10)); //true
- is_int32
is_int32(string | int | float | null $value): bool
— Alias for is_actual_int()- is_int64
is_int64(string | int | float | null $value): bool
— Alias for is_actual_long()- is_natural
is_natural(string | int | float | null $value): bool
This predicate returns true if $value is within all whole numbers - positive integers excluding zero. Returns false if $value is an e-notated value
When a number exceeds
C_LONG_MAX
a 'natural number' is then considered as any float value with a.00
scale-
Examples
var_dump(is_natural(-1)); //false var_dump(is_natural('0')); //false var_dump(is_natural(1e+10)); //false var_dump(is_natural('1e+10')); //false var_dump(is_natural(1.5)); //false var_dump(is_natural(PHP_INT_MAX)); //true var_dump(is_natural(100)); //true var_dump(is_natural(PHP_INT_MIN)); //false var_dump(is_natural(PHP_INT_MAX + 1)); //true
- is_negative
is_negative(string | int | float | null $value): bool
This predicate returns true if $value is a negative number
-
Examples
var_dump(is_negative(-1)); //true var_dump(is_negative('0')); //false var_dump(is_negative(PHP_INT_MIN)); //true var_dump(is_negative(-.5)); //true var_dump(is_negative(PHP_INT_MAX)); //false
- is_non_zero
is_non_zero(string | int | float | null $value): bool
This predicate returns true if $value is any number other than 0
-
Examples
var_dump(is_non_zero(-1)); //true var_dump(is_non_zero('0')); //false var_dump(is_non_zero(0)); //false var_dump(is_non_zero("abc")); //false var_dump(is_non_zero(1e+10)); //true
- is_odd
is_odd(string | int | float | null $value): bool
This predicate returns true if $value is an odd number
-
Examples
var_dump(is_odd(0)); //false var_dump(is_odd('1')); //true var_dump(is_odd(-101)); //true var_dump(is_odd(3)); //true var_dump(is_odd(3.00)); //true
- is_perfect
is_perfect(string | int | float | null $value): bool
This predicate returns true if $value is a perfect number
A perfect number
n
is a natural number that is equal to the sum of the proper divisors ofn
For example, 28 is a perfect number because:
- It is a natural number
- The sum of all divisors of 28, less than 28 =
1 + 2 + 4 + 7 + 14
=28
- is_positive
is_positive(string | int | float | null $value): bool
This predicate returns true if $value is a positive number
-
Examples
var_dump(is_positive(-1)); //false var_dump(is_positive('0')); //false var_dump(is_positive(PHP_INT_MIN)); //false var_dump(is_positive(.5)); //true var_dump(is_positive(PHP_INT_MAX)); //true var_dump(is_positive(1e+10)); //true
- is_prime
is_prime(string | int | float | null $value): bool
This predicate returns true if the provided value is a positive integer, or a numeric string without decimals and is not an e-notated number/numeric string
This method will first attempt to use built-in functions if they exist (bcmath, gmp)
- is_short
is_short(string | int | float | null $value): bool
— Alias for is_actual_short()- is_sum_product
is_sum_product(string | int | float | null $value): bool
This predicate returns true if $value is a sum product number
A sum product number
n
is a whole number that the sum of the products of each ofn
digit equalsn
For example, 144 is a sum product number because:
- It is a whole number
- Each digits product equals the sum of each digit
(1 * 4 * 4) = 16 * (1 + 4 + 4) = 9 ---- 144
- is_ubyte
is_ubyte(string | int | float | null $value): bool
This predicate returns true if
0 >= $value <= C_UBYTE_MAX
and is not an e-notated value-
Examples
var_dump(is_ubyte(-1)); //false var_dump(is_ubyte('0')); //true var_dump(is_ubyte(.5)); //false var_dump(is_ubyte(255)); //true var_dump(is_ubyte(256)); //false
- is_uint32
is_uint32(string | int | float | null $value): bool
This predicate returns true if
0 >= $value <= C_UINT_MAX
and is not an e-notated value-
Examples
var_dump(is_uint32(-1)); //false var_dump(is_uint32('0')); //true var_dump(is_uint32(.5)); //false var_dump(is_uint32(4_294_967_295)); //true var_dump(is_uint32(4_294_967_296)); //false
- is_uint64
is_uint64(string | int | float | null $value): bool
This predicate returns true if
0 >= $value <= C_ULONG_MAX
and $value is a string and only a string value compared bybccomp
and is not an e-notated number/numeric string-
Examples
var_dump(is_uint64(-1)); //false var_dump(is_uint64('0')); //true var_dump(is_uint64(.5)); //false var_dump(is_uint64(C_UINT_MAX + 1)); //true var_dump(is_uint64('9223372036854775808')); //true var_dump(is_uint64('18446744073709551615')); //true var_dump(is_uint64('18446744073709551616')); //false
var_dump(is_uint64(PHP_INT_MAX + 1)); //false
- is_ushort
is_ushort(string | int | float | null $value): bool
This predicate returns true if
0 >= $value <= C_USHORT_MAX
and is not an e-notated number/numeric string-
Examples
var_dump(is_ushort(-1)); //false var_dump(is_ushort('0')); //true var_dump(is_ushort(.5)); //false var_dump(is_ushort(65535)); //true var_dump(is_ushort(C_USHORT_MAX + 1)); //false
- is_whole
is_whole(string | int | float | null $value): bool
This predicate returns true if $value is a natural number, including zero
-
Examples
var_dump(is_whole(-1)); //false var_dump(is_whole('0')); //true var_dump(is_whole(1e+10)); //false var_dump(is_whole('1e+10')); //false var_dump(is_whole(1.5)); //false var_dump(is_whole(PHP_INT_MAX)); //true var_dump(is_whole(100)); //true var_dump(is_whole(PHP_INT_MIN)); //false var_dump(is_whole(PHP_INT_MAX + 1)); //true
- is_zero
is_zero(string | int | float | null $value): bool
This predicate returns true if $value is 0
-
Examples
var_dump(is_zero(-1)); //false var_dump(is_zero('0')); //true var_dump(is_zero(0)); //true var_dump(is_zero("abc")); //false var_dump(is_zero(1e+10)); //false
Strings
- has_alpha
has_alpha(?string $value): bool
This predicate returns true if any character in $value is alpha as defined by
IntlChar::isUAlphabetic()
-
Examples
var_dump(has_alpha(' aoeuhtns12 3')); //true var_dump(has_alpha('a0eu.1')); //true var_dump(has_alpha('a!@#$eu ')); //true var_dump(has_alpha('')); //false var_dump(has_alpha(' ')); //false var_dump(has_alpha(' 123 ')); //false var_dump(has_alpha(' !@#$%')); //false
- has_digit
has_digit(?string $value): bool
This predicate returns true if any character in $value is a digit as defined by
IntlChar::isdigit()
-
Examples
var_dump(has_digit(' aoeuhtns12 3')); //true var_dump(has_digit('a0eu.1')); //true var_dump(has_digit('a!@#$eu ')); //false var_dump(has_digit('')); //false var_dump(has_digit(' ')); //false var_dump(has_digit(' 123 ')); //true var_dump(has_digit(' !@#$%')); //false
- has_punctuation
has_punctuation(?string $value): bool
This predicate returns true if any character in $value is punctuation - any printable character that is not
IntlChar::isdigit
and notIntlChar::isblank
and notIntlChar::isUAlphabetic
which emulatesctype_punct()
-
Examples
var_dump(has_punctuation(' aoeuhtns12 3')); //false var_dump(has_punctuation('a0eu.1')); //true var_dump(has_punctuation('a!@#$eu ')); //true var_dump(has_punctuation('')); //false var_dump(has_punctuation(' ')); //false var_dump(has_punctuation(' 123 ')); //false
- has_text
has_text(?string $value): bool
This predicate returns true if there are any non-whitespace characters in $value
-
Examples
var_dump(has_text('a0eu.1')); //true var_dump(has_text('')); //false var_dump(has_text(' ')); //false var_dump(has_text(' 123 ')); //true
- has_whitespace
has_whitespace(?string $value): bool
This predicate returns true if any of the characters in $value is a whitespace character as defined by
IntlChar::isUWhitespace()
-
Examples
var_dump(has_whitespace('a0eu.1')); //false var_dump(has_whitespace('')); //false var_dump(has_whitespace(' ')); //true var_dump(has_whitespace(' 123 ')); //true //vertical tab var_dump(has_whitespace(mb_chr(013))); //true
- is_alpha
is_alpha(?string $value): bool
This predicate returns if all characters in $value is alpha as defined by
IntlChar::isUAlphabetic()
-
Examples
var_dump(is_alpha('a0eu.1')); //false var_dump(is_alpha('')); //false var_dump(is_alpha(' ')); //false var_dump(is_alpha(' 123 ')); //false var_dump(is_alpha('aoeuhtns')); //true
- is_date
is_date(?string $value): bool
This predicate returns true if $value can be parsed using
strtotime()
-
Examples
var_dump(is_date('')); //false var_dump(is_date(123456890)); //false var_dump(is_date(' 2012-02-01')); //true var_dump(is_date('2012-02-01')); //true var_dump(is_date('2012-02-01T00:00Z')); //true var_dump(is_date('T00:00Z')); //true
- is_digit
is_digit(?string $value): bool
This predicate returns true if all characters in $value are digits as defined by
IntlChar::isdigit()
-
Examples
var_dump(is_digit('')); //false var_dump(is_digit('12345 ')); //false var_dump(is_digit('12345')); //true var_dump(is_digit(12345)); //true
- is_e_notation
is_e_notation(?string $value): bool
This predicate returns true if $value is an e-notated number/numeric string
-
Examples
var_dump(is_e_notation(1e0)); //false var_dump(is_e_notation('1e10')); //true var_dump(is_e_notation('1e+10')); //true var_dump(is_e_notation('1e-10')); //true var_dump(is_e_notation(PHP_INT_MAX + 1)); //true
- is_email
is_email(?string $value): bool
This predicate returns true if $value is a valid email as defined by
filter_var()
-
Examples
var_dump(is_email('example@example')); //false var_dump(is_email('example@example.com')); //true var_dump(is_email('Abc\@def@example.com')); //false var_dump(is_email('Fred\ Bloggs@example.com')); //false var_dump(is_email('$A12345@example.com')); //true var_dump(is_email('customer/department=shipping@example.com')); //true
- is_ip
is_ip(?string $value): bool
This predicate returns true if $value is an ip address as defined by
filter_var()
-
Examples
var_dump(is_ip('127.16.0.0')); //true var_dump(is_ip('128.66.0.0/16')); //false var_dump(is_ip('2001:DB8:0:0:8:800:200C:417A')); //true var_dump(is_ip('0:0:0:0:0:0:0:1')); //true var_dump(is_ip('FF01::101')); //true var_dump(is_ip('::')); //true var_dump(is_ip('::1')); //true
- is_ipv4
is_ipv4(?string $value): bool
This predicate returns true if $value is an ipv4 address as defined by
filter_var()
- is_ipv6
is_ipv6(?string $value): bool
This predicate returns true if $value is an ipv6 address as defined by
filter_var()
- is_lower_strict
is_lower_strict(?string $value): bool
This predicate returns true if all of the characters in the string are lowercase as defined by
IntlChar::isULowercase()
-
Examples
var_dump(is_lower_strict('aAeuhtns')); //false var_dump(is_lower_strict('')); //false var_dump(is_lower_strict(' aaeuhtns')); //false var_dump(is_lower_strict('aaeuhtns')); //true
- is_lower
is_lower(?string $value): bool
This predicate returns true if all the alpha characters in a string are lowercase as, omitting whitespace and punctuation from validation as defined by
IntlChar::isULowercase()
-
Examples
var_dump(is_lower('aAeuhtns')); //false var_dump(is_lower('')); //false var_dump(is_lower(' aaeuhtns99')); //true var_dump(is_lower('aaeuhtns99')); //true
- is_ltrimmed
is_ltrimmed(?string $value): bool
This predicate returns true if $value is not null and the start of $value does not contain whitespace
-
Examples
var_dump(is_ltrimmed(' aoeuhtns')); //false var_dump(is_ltrimmed(' ')); //false var_dump(is_ltrimmed(' aoeuhtns ')); //false var_dump(is_ltrimmed(' ')); //false var_dump(is_ltrimmed('aoeuhtns ')); //true var_dump(is_ltrimmed('')); //true
- is_punctuation
is_punctuation(?string $value): bool
This predicate returns true if all characters in $value are punctuation characters - any printable character that is not
IntlChar::isdigit
and notIntlChar::isblank
and notIntlChar::isUAlphabetic
which emulatesctype_punct()
-
Examples
var_dump(is_punctuation('$1,000')); //false var_dump(is_punctuation('!@#$%')); //true var_dump(is_punctuation(' ... ')); //false var_dump(is_punctuation('...')); //true
- is_regex
is_regex(?string $value): bool
This predicate returns true if $value is a valid regular expression
-
Examples
var_dump(is_regex('')); //false var_dump(is_regex(' ')); //true var_dump(is_regex('!@#$%')); //true var_dump(is_regex('.*')); //true var_dump(is_regex('/.*/')); //true var_dump(is_regex('//.*/')); //false
- is_rtrimmed
is_rtrimmed(?string $value): bool
This predicate returns true if $value is not null and the end of $value does not contain whitespace
-
Examples
var_dump(is_rtrimmed('aoeuhtns ')); //false var_dump(is_rtrimmed(' ')); //false var_dump(is_rtrimmed(' aoeuhtns ')); //false var_dump(is_rtrimmed(' ')); //false var_dump(is_rtrimmed(' aoeuhtns')); //true var_dump(is_rtrimmed('')); //true
- is_trimmed
is_trimmed(?string $value): bool
This predicate returns true if $value is not null and both
r_trimmed()
andl_trimmed()
-
Examples
var_dump(is_trimmed('aoeuhtns ')); //false var_dump(is_trimmed(' aoeuhtns ')); //false var_dump(is_trimmed(' aoeuhtns')); //false var_dump(is_trimmed(' ')); //false var_dump(is_trimmed('')); //true var_dump(is_trimmed('aoeuhtns')); //true
- is_upper_strict
is_upper_strict(?string $value): bool
This predicate returns true if all of the characters in the string are uppercase as defined by
IntlChar::isUUppercase()
-
Examples
var_dump(is_upper_strict('aAeuhtns')); //false var_dump(is_upper_strict('')); //false var_dump(is_upper_strict(' AAEUHTNS')); //false var_dump(is_upper_strict('AAEUHTNS99')); //false var_dump(is_upper_strict('AAEUHTNS')); //true
- is_upper
is_upper(?string $value): bool
This predicate returns true if all the alpha characters in a string are uppercase, omitting whitespace and punctuation from validation as defined by
IntlChar::isUUppercase()
-
Examples
var_dump(is_upper('aAeuhtns')); //false var_dump(is_upper('')); //false var_dump(is_upper(' AAEUHTNS')); //true var_dump(is_upper('AAEUHTNS99')); //true
- is_url
is_url(?string $value): bool
This predicate returns true if $value is a valid url as defined by
filter_var()
-
Examples
var_dump(is_url('http://')); //false var_dump(is_url('http://localhost')); //true var_dump(is_url('http://localhost:8080')); //true var_dump(is_url('http://user:password@example.com')); //true
- is_us_phone
is_us_phone(?string $value): bool
This predicate returns true if $value is a valid United States phone number
The following conditions statisfy a 'us phone' format:
[2-9]#########
(10 digits starting with any number 2-9)[2-9]## ### ####
(10 digits with spaces between parts)[2-9]##.###.####
(10 digits with decimals between parts)[2-9]##-###-####
(10 digits with hyphens between parts)###-####
(7 digits with hyphens between parts)###.####
(7 digits with decimals between parts)### ####
(7 digits with spaces between parts)#######
(7 digits)
- is_us_state_abbr
is_us_state_abbr(?string $value): bool
This predicate returns true if $value is a valid Unite States state abbreviation
- is_us_state_name
is_us_state_name(?string $value): bool
This predicate returns true if $value is a valid Unite States state name
- is_us_state
is_us_state(?string $value): bool
This predicate returns true if $value is a valid Unite States state name or United States state abbreviation
- is_us_territory
is_us_territory(?string $value): bool
This predicate returns true if $value is a valid United States territory name
- is_whitespace
is_whitespace(?string $value): bool
This predicate returns true if all characters in $value are whitespace characters as defined by
IntlChar::isUWhitespace()
-
Examples
var_dump(is_whitespace('')); //false var_dump(is_whitespace(' A')); //false var_dump(is_whitespace(' ')); //true var_dump(is_whitespace(mb_chr(013))); //true
Dates
- is_afternoon
is_afternoon(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a locale-aware period of 'afternoon'
not all locales have an afternoon idiom
For more info see https://unicode-org.github.io/cldr-staging/charts/38/supplemental/day_periods.html
When $value is null, the current timestamp is used
-
Examples
var_dump(is_afternoon()); var_dump(is_afternoon('T00:00 UTC')); //false var_dump(is_afternoon('T03:00 UTC')); //false var_dump(is_afternoon('T05:59 UTC')); //false var_dump(is_afternoon('T06:00 UTC')); //false var_dump(is_afternoon('T11:59 UTC')); //false var_dump(is_afternoon('T12:00 UTC')); //true var_dump(is_afternoon('T12:59 UTC')); //true var_dump(is_afternoon('T13:00 UTC')); //true var_dump(is_afternoon('T15:00 UTC')); //true var_dump(is_afternoon('T17:59 UTC')); //true var_dump(is_afternoon('T18:00 UTC')); //false var_dump(is_afternoon('T20:59 UTC')); //false var_dump(is_afternoon('T21:00 UTC')); //false var_dump(is_afternoon('T23:59 UTC')); //false var_dump(is_afternoon('T24:00 UTC')); //false
- is_am
is_am(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a meridiem value of 'am'
When $value is null, the current timestamp is used
-
Examples
var_dump(is_am()); var_dump(is_am('T00:00 UTC')); //true var_dump(is_am('T03:00 UTC')); //true var_dump(is_am('T05:59 UTC')); //true var_dump(is_am('T06:00 UTC')); //true var_dump(is_am('T11:59 UTC')); //true var_dump(is_am('T12:00 UTC')); //false var_dump(is_am('T12:59 UTC')); //false var_dump(is_am('T13:00 UTC')); //false var_dump(is_am('T15:00 UTC')); //false var_dump(is_am('T17:59 UTC')); //false var_dump(is_am('T18:00 UTC')); //false var_dump(is_am('T20:59 UTC')); //false var_dump(is_am('T21:00 UTC')); //false var_dump(is_am('T23:59 UTC')); //false var_dump(is_am('T24:00 UTC')); //false
- is_dayofweek
is_dayofweek(?string $value): bool
This predicate returns true if $value is a day of week name or day of week abbreviation or day of week number
Not every locale has an english counterpart
It would not necessarily be locale-aware to include english versions of days of week as fallbacks. It is a decision made to honor whatever the
IntlCalendar
considers a weekday for the given region and locale and nothing else.An example of this is given below with the locale of
de_DE
.English fallbacks would be the responsibility of the consumer of this package
-
Examples
var_dump(is_dayofweek('monday')); //true var_dump(is_dayofweek('tue')); //true var_dump(is_dayofweek(0)); //false var_dump(is_dayofweek(1)); //true var_dump(is_dayofweek(7)); //true
var_dump(is_dayofweek('monday')); //true var_dump(is_dayofweek('월요일')); //true var_dump(is_dayofweek(0)); //false var_dump(is_dayofweek(1)); //true var_dump(is_dayofweek(7)); //true
var_dump(is_dayofweek('monday')); //false var_dump(is_dayofweek('월요일')); //false var_dump(is_dayofweek('montag')); //true var_dump(is_dayofweek(0)); //false var_dump(is_dayofweek(1)); //true var_dump(is_dayofweek(7)); //true
- is_end_of_month
is_end_of_month(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value is greater than or equal to the last half of the $value month
When $value is null, the current timestamp is used
The end of month is calculated as such:
$value >= floor(max_days_in_month / 2)
-
Examples
var_dump(is_end_of_month()); var_dump(is_end_of_month('2023-01-01')); //false var_dump(is_end_of_month('2023-01-14')); //false var_dump(is_end_of_month('2023-01-15')); //true
- is_evening
is_evening(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a locale-aware period of 'evening'
not all locales have an evening idiom
For more info see https://unicode-org.github.io/cldr-staging/charts/38/supplemental/day_periods.html
When $value is null, the current timestamp is used
-
Examples
var_dump(is_evening()); var_dump(is_evening('T00:00 UTC')); //false var_dump(is_evening('T03:00 UTC')); //false var_dump(is_evening('T05:59 UTC')); //false var_dump(is_evening('T06:00 UTC')); //false var_dump(is_evening('T11:59 UTC')); //false var_dump(is_evening('T12:00 UTC')); //false var_dump(is_evening('T12:59 UTC')); //false var_dump(is_evening('T13:00 UTC')); //false var_dump(is_evening('T15:00 UTC')); //false var_dump(is_evening('T17:59 UTC')); //false var_dump(is_evening('T18:00 UTC')); //true var_dump(is_evening('T20:59 UTC')); //true var_dump(is_evening('T21:00 UTC')); //false var_dump(is_evening('T23:59 UTC')); //false var_dump(is_evening('T24:00 UTC')); //false
- is_future
is_future(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is in the future
-
Examples
var_dump(is_future('2999-12-31T00:00 UTC')); //true var_dump(is_future('1999-12-31T00:00 UTC')); //false var_dump(is_future('+1 day')); //true var_dump(is_future('-1 day')); //false
- is_last_month
is_last_month(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within last month
-
Examples
var_dump(is_last_month('december')); //true var_dump(is_last_month('dec')); //true var_dump(is_last_month('12')); //true var_dump(is_last_month(12)); //true var_dump(is_last_month('-1 month')); //true var_dump(is_last_month(new DateTime('1999-12-31'))); //false
var_dump(is_last_month('december')); //true var_dump(is_last_month('십이월')); //true
- is_last_quarter
is_last_quarter(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within the last quarter, cycling
-
Examples
var_dump(is_last_quarter(1)); //false var_dump(is_last_quarter(4)); //true var_dump(is_last_quarter('04')); //true var_dump(is_last_quarter('2022-09-01')); //false var_dump(is_last_quarter('1999-10-01')); //false var_dump(is_last_quarter('2022-10-01')); //true
- is_last_year
is_last_year(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within last year
-
Examples
var_dump(is_last_year('2022-09-01')); //true var_dump(is_last_year('1999-10-01')); //false var_dump(is_last_year('2022')); //true var_dump(is_last_year(2022)); //true
- is_leap_year
is_leap_year(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value is a leap year
When $value is null, the current timestamp is used
-
Examples
var_dump(is_leap_year()); var_dump(is_leap_year('2022-09-01')); //false var_dump(is_leap_year('2020')); //true var_dump(is_leap_year(2024)); //true
- is_midnight
is_midnight(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value is midnight (either 24:00 or 00:00)
When $value is null, the current timestamp is used
-
Examples
var_dump(is_midnight()); var_dump(is_midnight('T00:00 UTC')); //true var_dump(is_midnight('T03:00 UTC')); //false var_dump(is_midnight('T05:59 UTC')); //false var_dump(is_midnight('T06:00 UTC')); //false var_dump(is_midnight('T11:59 UTC')); //false var_dump(is_midnight('T12:00 UTC')); //false var_dump(is_midnight('T12:59 UTC')); //false var_dump(is_midnight('T13:00 UTC')); //false var_dump(is_midnight('T15:00 UTC')); //false var_dump(is_midnight('T17:59 UTC')); //false var_dump(is_midnight('T18:00 UTC')); //false var_dump(is_midnight('T20:59 UTC')); //false var_dump(is_midnight('T21:00 UTC')); //false var_dump(is_midnight('T23:59 UTC')); //false var_dump(is_midnight('T24:00 UTC')); //true
- is_month_abbr
is_month_abbr(?string $value): bool
This predicate returns true if $value is a month abbreviation
Use's english fallbacks in addition to any translated or supported locale specific values
- is_month_name
is_month_name(?string $value): bool
This predicate returns true if $value is a month's name
Use's english fallbacks in addition to any translated or supported locale specific values
- is_month
is_month(string | int | null $value): bool
This predicate returns true if $value is a month name or month abbreviation or month number (0?1-12)
Use's english fallbacks in addition to any translated or supported locale specific values
-
Examples
var_dump(is_month(0)); //false var_dump(is_month(1)); //true var_dump(is_month('1')); //true var_dump(is_month('04')); //true var_dump(is_month('jan')); //true var_dump(is_month('DECEMBER')); //true
var_dump(is_month('DECEMBER')); //true var_dump(is_month('십이월')); //true
- is_morning
is_morning(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a locale-aware period of 'morning'
not all locales have a morning idiom
For more info see https://unicode-org.github.io/cldr-staging/charts/38/supplemental/day_periods.html
When $value is null, the current timestamp is used
-
Examples
var_dump(is_morning()); var_dump(is_morning('T00:00 UTC')); //false var_dump(is_morning('T03:00 UTC')); //false var_dump(is_morning('T05:59 UTC')); //false var_dump(is_morning('T06:00 UTC')); //true var_dump(is_morning('T11:59 UTC')); //true var_dump(is_morning('T12:00 UTC')); //false var_dump(is_morning('T12:59 UTC')); //false var_dump(is_morning('T13:00 UTC')); //false var_dump(is_morning('T15:00 UTC')); //false var_dump(is_morning('T17:59 UTC')); //false var_dump(is_morning('T18:00 UTC')); //false var_dump(is_morning('T20:59 UTC')); //false var_dump(is_morning('T21:00 UTC')); //false var_dump(is_morning('T23:59 UTC')); //false var_dump(is_morning('T24:00 UTC')); //false
- is_next_month
is_next_month(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within next month
-
Examples
var_dump(is_next_month('feb')); //true var_dump(is_next_month('02')); //true var_dump(is_next_month(2)); //true var_dump(is_next_month(new DateTime('1999-02-01'))); //false
var_dump(is_next_month('february')); //true var_dump(is_next_month('이월')); //true
- is_next_quarter
is_next_quarter(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within the next quarter, cycling
-
Examples
var_dump(is_next_quarter(1)); //false var_dump(is_next_quarter(2)); //true var_dump(is_next_quarter('02')); //true var_dump(is_next_quarter('2023-03-01')); //false var_dump(is_next_quarter('1999-04-01')); //false var_dump(is_next_quarter('2023-04-01')); //true
- is_next_year
is_next_year(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within next year
-
Examples
var_dump(is_next_year('2024-09-01')); //true var_dump(is_next_year('1999-10-01')); //false var_dump(is_next_year('2024')); //true var_dump(is_next_year(2024)); //true
- is_noon
is_noon(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a meridiem value of 'noon'
not all locales have a noon idiom
For more info see https://www.unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rules
When $value is null, the current timestamp is used
-
Examples
var_dump(is_noon()); var_dump(is_noon('T00:00 UTC')); //false var_dump(is_noon('T03:00 UTC')); //false var_dump(is_noon('T05:59 UTC')); //false var_dump(is_noon('T06:00 UTC')); //false var_dump(is_noon('T11:59 UTC')); //false var_dump(is_noon('T12:00 UTC')); //true var_dump(is_noon('T12:59 UTC')); //true var_dump(is_noon('T13:00 UTC')); //false var_dump(is_noon('T15:00 UTC')); //false var_dump(is_noon('T17:59 UTC')); //false var_dump(is_noon('T18:00 UTC')); //false var_dump(is_noon('T20:59 UTC')); //false var_dump(is_noon('T21:00 UTC')); //false var_dump(is_noon('T23:59 UTC')); //false var_dump(is_noon('T24:00 UTC')); //false
- is_past
is_past(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is in the past
-
Examples
var_dump(is_past('2999-12-31T00:00 UTC')); //false var_dump(is_past('1999-12-31T00:00 UTC')); //true var_dump(is_past('+1 day')); //false var_dump(is_past('-1 day')); //true
- is_pm
is_pm(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value has a meridiem value of 'pm'
When $value is null, the current timestamp is used
-
Examples
var_dump(is_pm()); var_dump(is_pm('T00:00 UTC')); //false var_dump(is_pm('T03:00 UTC')); //false var_dump(is_pm('T05:59 UTC')); //false var_dump(is_pm('T06:00 UTC')); //false var_dump(is_pm('T11:59 UTC')); //false var_dump(is_pm('T12:00 UTC')); //true var_dump(is_pm('T12:59 UTC')); //true var_dump(is_pm('T13:00 UTC')); //true var_dump(is_pm('T15:00 UTC')); //true var_dump(is_pm('T17:59 UTC')); //true var_dump(is_pm('T18:00 UTC')); //true var_dump(is_pm('T20:59 UTC')); //true var_dump(is_pm('T21:00 UTC')); //true var_dump(is_pm('T23:59 UTC')); //true var_dump(is_pm('T24:00 UTC')); //false
- is_start_of_month
is_start_of_month(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value is less than or equal to the first half of the $value month
When $value is null, the current timestamp is used
The start of month is calculated as such:
$value <= floor(max_days_in_month / 2)
-
Examples
var_dump(is_start_of_month()); var_dump(is_start_of_month('2023-01-01')); //true var_dump(is_start_of_month('2023-01-15')); //true var_dump(is_start_of_month('2023-01-16')); //false
- is_this_month
is_this_month(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within this month
-
Examples
var_dump(is_this_month('january')); //true var_dump(is_this_month('jan')); //true var_dump(is_this_month('01')); //true var_dump(is_this_month(1)); //true var_dump(is_this_month('3000-01-15')); //false var_dump(is_this_month('2023-01-15')); //true
- is_this_quarter
is_this_quarter(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within this quarter
-
Examples
var_dump(is_this_quarter(1)); //true var_dump(is_this_quarter('01')); //true var_dump(is_this_quarter('1999-01-01')); //false var_dump(is_this_quarter('2023-01-01')); //true var_dump(is_this_quarter('2023-04-01')); //false
- is_this_year
is_this_year(string | DateTimeInterface | null $value): bool
This predicate returns true if $value falls within this year
-
Examples
var_dump(is_this_year('2022-09-01')); //false var_dump(is_this_year('2022')); //false var_dump(is_this_year(2023)); //true var_dump(is_this_year(new DateTime('first day of this year'))); //true
- is_today
is_today(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is today
-
Examples
var_dump(is_today('01')); //true var_dump(is_today(1)); //true var_dump(is_today('sun'))); //true var_dump(is_today('sunday'))); //true var_dump(is_today(new DateTime('2022-01-01'))); //false var_dump(is_today(new DateTime('2023-01-01'))); //true
- is_tomorrow
is_tomorrow(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is tomorrow
-
Examples
var_dump(is_tomorrow('02')); //true var_dump(is_tomorrow(2)); //true var_dump(is_today('mon'))); //true var_dump(is_today('monday'))); //true var_dump(is_tomorrow(new DateTime('2022-01-02'))); //false var_dump(is_tomorrow(new DateTime('+1 day'))); //true
- is_us_holiday
is_us_holiday(string | DateTimeInterface | null $value = null): bool
This predicate returns true if $value lands on a fixed or observed us federal holiday for $value year
When $value is null, the current timestamp is used
This method accounts for when the holiday was established. For example, if the date is
Jan 1st 1869
, it will not be New Years since the holiday was established in 1870-
Examples
var_dump(is_us_holiday()); var_dump(is_us_holiday('2023-01-01')); //true var_dump(is_us_holiday('fourth thursday of November this year')); //true var_dump(is_us_holiday('fourth thursday of November 2024')); //true var_dump(is_us_holiday('2023-12-25')); //true
- is_weekday
is_weekday(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is a week day name or weekday abbreviation or a weekday number
-
Examples
var_dump(is_weekday()); var_dump(is_weekday('sat')); //false var_dump(is_weekday('saturday')); //false var_dump(is_weekday('7')); //false var_dump(is_weekday('mon')); //true
var_dump(is_weekday('יום שישי')); //friday false var_dump(is_weekend_day('יום שישי')); //friday true
- is_weekend_day
is_weekend_day(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is a weekend day name or weekend day abbreviation or weekend day number
-
Examples
var_dump(is_weekend_day()); var_dump(is_weekend_day('sat')); //true var_dump(is_weekend_day('saturday')); //true var_dump(is_weekend_day('7')); //true var_dump(is_weekend_day('mon')); //false
var_dump(is_weekday('יום שישי')); //friday false var_dump(is_weekend_day('יום שישי')); //friday true
- is_within_date_range
is_within_date_range(string | DateTimeInterface | null $value, string $relative_format): bool
This predicate returns true if $value is within the date range provided compared to
now
Identify if a given value is within a specified date range comparing its relative timestamp to
now
For example:
is_within_date_range($date, '+-5 mins')
The expectation in that example is that $date should be a date within plus or minus 5 mins of
now
For example, assume the current time (
now
) isT16:00 UTC
is_within_date_range('T15:54 UTC', '+-5 mins'); //false because 6 mins ago is_within_date_range('T15:55 UTC', '+-5 mins'); //true because 5 mins ago is_within_date_range('T15:56 UTC', '+-5 mins'); //true because 4 mins ago is_within_date_range('T16:00 UTC', '+-5 mins'); //true because now is_within_date_range('T16:04 UTC', '+-5 mins'); //true because in 4 mins is_within_date_range('T16:05 UTC', '+-5 mins'); //true because in 5 mins is_within_date_range('T16:06 UTC', '+-5 mins'); //false because 1 min over
Plus or Minus Syntax
When a plus or minus symbol is omitted, the default is
-
(in the past)is_within_date_range($date, '+-5 mins')
means $date should be + or minus 5 mins fromnow
is_within_date_range($date, '-5 mins)
means $date should be after 5 mins ago fromnow
but not afternow
is_within_date_range($date, '+5 mins)
means $date should be betweennow
andnow +5 mins
is_within_date_range($date, '-+5 mins')
-+
is not supported, it must be plus or minus
Relative Format
The $relative_format parameter is a custom subset of the php relative formats, it's effectively all daytext and unit symbols with additional support for a
+
or-
prefixThe complete $relative_format regex pattern is as follows:
/^ (\+\-|[\+\-])? //optionally start with plus or minus ([0-9]+) //1 or more numbers [ \t]+ //1 or more space or tabs (ms|µs|weeks| (?:msec|millisecond|µsec|microsecond|usec|sec(ond)?|min(ute)?|hour|day|fortnight|forthnight|month|year|weekday)[s]? ) //required unit $/
See: https://www.php.net/manual/en/datetime.formats.relative.php
-
Examples
var_dump(is_within_date_range('-1 min', '+-5 min')); //true var_dump(is_within_date_range('24 hours', '+-1 weeks')); //true var_dump(is_within_date_range('+5 hours', '-24 hours')); //false var_dump(is_within_date_range(new DateTime('last thursday'), '1 weeks')); //true var_dump(is_within_date_range(new DateTime('last thursday'), '+1 weeks')); //false var_dump(is_within_date_range(new DateTime('last thursday'), '-1 weeks')); //true var_dump(is_within_date_range(new DateTime('last thursday'), '+-1 weeks')); //true
- is_yesterday
is_yesterday(string | DateTimeInterface | null $value): bool
This predicate returns true if $value is yesterday
-
Examples
var_dump(is_yesterday('31')); //true var_dump(is_yesterday(31)); //true var_dump(is_yesterday('saturday')); //true var_dump(is_yesterday('sat')); //true var_dump(is_yesterday(new DateTime('2022-12-31T13:00'))); //true
Constants
This package contributes the following global constants
Numbers
- C_BYTE_MAX
- <int> 127
- C_BYTE_MIN
- <int> -128
- C_INT_MAX
- <int> 2147483647
- C_INT_MIN
- <int> -2147483648
- C_LONG_MAX
- <int> 9223372036854775807
- C_LONG_MIN
- <int> -9223372036854775808
- C_SHORT_MAX
- <int> 32767
- C_SHORT_MIN
- <int> -32768
- C_UBYTE_MAX
- <int> 255
- C_UINT_MAX
- <int> 4294967295
- C_ULONG_MAX
- <string> 18446744073709551615
- C_USHORT_MAX
- <int> 65535
- GMP_PRIME_FALSE
- <int> 0
- GMP_PRIME_POSSIBLE
- <int> 1
- GMP_PRIME_TRUE
- <int> 2
Dates
- RFC3339_FULL_DATE
- Y-m-d
- RFC3339_HOUR
- H
- RFC3339_MINUTE
- i
- RFC3339_MONTH_DAY
- d
- RFC3339_MONTH
- m
- RFC3339_SECOND
- s
- RFC3339_YEAR
- Y
Localization
Most predicates are locale-aware; meaning they automatically adjust validations to the locale provided. For example, in United States, the decimal separator is a period (.
) while in France it is a comma (,
)
Therefore a predicate like is_actual_float
would validate accordingly to the locale. In United States, 1.5
would return true while for France it would only be true if the comma was used: 1,5
and in United States, 1,5
would return false
Reasons why you would want to dynamically change locale is for many scenarios, most commonly is to load a page using the locale via lang
env var or from the HTTP_ACCEPT
header as to not use the server locale or php.ini value
How ft/predicates Localization Works
This package does not change any underlying configurations. Meaning, we do not call
setlocale
orLocale::setDefault()
. We simply obtain the locale how you tell us and use that locale value within the scope of our needs
Although this package does not change any configurations it tries it's best to align and honor normal php conventions, like obtaining the locale from php.ini for example
The order of which locale is obtained by this package is as follows:
- Default to php.ini configurations
- If an env variable
ft.ini
exists- Get ft.ini file using
getenv('ft.ini')
- If file exists
- Retrieve the
locale_id_strategy
value if it exists - Else use defaults
- Retrieve the
- If file does not exist
- Retrieve value from
getenv('ft.predicates.locale_id_strategy')
if it exists - Else use defaults
- Retrieve value from
- Get ft.ini file using
In short, you can either tell the package which locale to use by telling it where to look for that value using either an ft.ini file or by setting the values directly using putenv
or simply do nothing and it will use the php.ini values
Once the locale is established, all the locale-aware predicates will validate against that locale inherently.
There is no cross-locale support. Meaning, if a locale does not recognize English 'Monday' as a day of the week it would return false for something like
is_dayofweek()
. Conversely, if a locale does recognize english 'Monday' as a day of week and this package supports translations for that locale, the translations will also be provided. An example of that iskr_KR
where eitheris_dayofweek('Monday')
andis_dayofweek('월요일')
would both return true
All locale-based logic is done using:
List of supported locales
All locales are supported that PHP supports (and the system)
It's hard to identify a complete list of supported locale identifiers because it heavily depends on the system. In fact, PHP docs state:
It is not recommended that the default
intl.default_locale
ini setting be relied on, as its effective value depends on the server's environment
You can however explore the built-in ICU locales: https://icu4c-demos.unicode.org/icu-bin/locexp#language
The meaning of 'supported' locales has two variants in this package
- A supported locale in general means any PHP recognized locale will be honored for any locale-aware predicates. For example, all
DateTime
objects will be formatted using that locale naturally - A 'supported' locale in the context of this package, means we have also added a translation file so that things like 'Monday' can be translated to the language of the provided locale when it is not an English language and the
IntlDateFormatter
returns an English value
Dynamically Update Locale Identifiers
The following alternatives to php.ini configs are supported for dynamically obtaining the locale identifier
- Create an ft.ini file and supply values there
- Once created, tell the package where to look with:
putenv('ft.ini=<ft.ini path>')
- Once created, tell the package where to look with:
- Tell ft/predicates where to look via
putenv
putenv('ft.predicates.locale_id_strategy=<choice>')
putenv('ft.predicates.locale_timezone_strategy=<choice>')
FT.INI
[predicates]
locale_id_strategy=<value>
locale_timezone_strategy=<value>
The 'predicates' ini section is required as this file may be used across many
ft
packages
- locale_id_strategy
-
Default:
Possible Values:php_ini
- php_ini — The locale is retrieved using
ini_get('intl.default_locale')
- env_var — The locale is retrieved using
getenv('lang')
- http_accept_header — The locale is retrieved using
$_SERVER['HTTP_ACCEPT']
- php_ini — The locale is retrieved using
- locale_timezone_strategy
-
Default:
Possible Values:none
- none -
$null
will be used - php_ini — The timezone is retrieved using
ini_get('date.timezone')
- env_var — The timezone is retrieved using
getenv('ft.predicates.default_timezone')
- none -
To let the package know you want it to use an ft.ini file simply call:
putenv("ft.ini=<ft.ini path>")