在PHP中,gettype()
函数用于确定变量的类型。当处理字符串时,gettype()
将返回字符串。下面是一个简单的示例:
<?php
$string = "Hello, World!";
echo gettype($string); // 输出: string
?>
在这个例子中,我们声明了一个名为$string
的变量,并将其值设置为字符串"Hello, World!"。然后,我们使用gettype()
函数来确定变量的类型,并将结果输出到屏幕上。输出结果为string
,表示变量是一个字符串。