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

phpis_string(mixed $var): bool

Example

Let's check a string variable:

php<?php
  $res = is_string('abcde');
  var_dump($res);
?>

Code execution result:

phptrue

Example

Let's check a numeric variable:

php<?php
  $res = is_string(12345);
  var_dump($res);
?>

Code execution result:

phpfalse

Example

Let's check an array variable:

php<?php
  $res = is_string(['a', 'b', 'c']);
  var_dump($res);
?>

Code execution result:

phpfalse

See Also

  • the is_int function,
    which checks if a variable is an integer
  • the is_array function,
    which checks if a variable is an array