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
廣告