PHP is_string() function
The PHP is_string() function is used to find whether a certain value is a string type.
The function syntax is as follows:
is_string(mixed $value): bool
This function accepts a value and returns true when that value is string type. Otherwise, it returns false.
Here are some examples of calling the function:
// ๐ pass variable to is_string
$int = 7;
var_dump(is_string($int)); // bool(false)
$str = "Hi";
var_dump(is_string($str)); // bool(true)
// ๐ pass direct value to is_string
var_dump(is_string([1, 3])); // bool(false)
var_dump(is_string(["H", "A"])); // bool(false)
var_dump(is_string(NULL)); // bool(false)
var_dump(is_string("789")); // bool(true)
Use the is_string() function when you need to check whether a variable is a string.
The returned boolean value can be used in an if-else conditional statement ๐
More PHP tutorials
See allPHP
PHP form validation basic example
Dec 22, 2022
PHP
PHP validate email address (with code examples)
Dec 22, 2022
PHP
How to redirect using PHP with code examples
Dec 22, 2022
PHP
Handling form data using PHP (GET and POST)
Dec 21, 2022
PHP
How to fix Wordpress PHP error missing MySQL extension
Dec 21, 2022