PHP - is_string() 函数



定义和用法

is_string() 函数用于检查变量的类型是否为字符串。

语法

bool is_string ( mixed $value )

参数

序号 参数及描述
1

要评估的变量。

返回值

如果 value 是字符串,则此函数返回 true,否则返回 false此函数不认为 NULL 是标量。

依赖项

PHP 4 及更高版本

示例

以下示例演示了 is_string() 函数的使用:

<?php
   $a = "Tutorialspoint";
   echo "a is ".( is_string($a)? 'string' : 'not string') . "<br>";

   $b = 0;
   echo "b is ".( is_string($b)? 'string' : 'not string') . "<br>";

   $c = 40;
   echo "c is ".( is_string($c)? 'string' : 'not string') . "<br>";

   $d = NULL;
   echo "d is ".( is_string($d)? 'string' : 'not string') . "<br>";

   $e = array("a", "b", "c");
   echo "e is ".( is_string($e)? 'string' : 'not string') . "<br>";

   $f = 3.1416;
   echo "f is ".( is_string($f)? 'string' : 'not string') . "<br>";

   $g = new stdClass();
   echo "g is ".( is_string($g)? 'string' : 'not string') . "<br>";

   $h = '';
   echo "h is ".( is_string($h)? 'string' : 'not string') . "<br>";
?>

输出

这将产生以下结果:

a is string
b is not string
c is not string
d is not string
e is not string
f is not string
g is not string
h is string
php_variable_handling_functions.htm
广告

© . All rights reserved.