is_string()

is_string() — Find whether the type of a variable is string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

is_string(mixed $value): bool

Parameters

ParameterTypeWhat it takes
$valuemixedThe variable being evaluated.

Return value

Returns true if value is of type string, false otherwise.

Example

A runnable snippet:

$values = array(false, true, null, 'abc', '23', 23, '23.5', 23.5, '', ' ', '0', 0); foreach ($values as $value) { echo "is_string("; var_export($value); echo ") = "; echo var_dump(is_string($value)); }

Output:

is_string(false) = bool(false) is_string(true) = bool(false) is_string(NULL) = bool(false) is_string('abc') = bool(true) is_string('23') = bool(true) is_string(23) = bool(false) is_string('23.5') = bool(true) is_string(23.5) = bool(false) is_string('') = bool(true) is_string(' ') = bool(true) is_string('0') = bool(true) is_string(0) = bool(false)

See also

is_float(), is_int(), is_bool(), is_object(), is_array()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page is_string() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.