The is_string Function
The is_string
function checks if the passed variable is a string. Returns true
if the variable contains a string, and false
otherwise. The function accepts one parameter - the variable to check.
Syntax
is_string(mixed $var): bool
Example
Let's check a string variable:
<?php
$res = is_string('abcde');
var_dump($res);
?>
Code execution result:
true
Example
Let's check a numeric variable:
<?php
$res = is_string(12345);
var_dump($res);
?>
Code execution result:
false
Example
Let's check an array variable:
<?php
$res = is_string(['a', 'b', 'c']);
var_dump($res);
?>
Code execution result:
false