gettype()
是 PHP 中的一个内置函数,用于获取变量的类型
<?php
$var1 = "Hello, World!";
$var2 = 42;
$var3 = 3.14;
$var4 = array(1, 2, 3);
$var5 = true;
$var6 = null;
echo "Type of var1 (string): " . gettype($var1) . "\n";
echo "Type of var2 (integer): " . gettype($var2) . "\n";
echo "Type of var3 (float): " . gettype($var3) . "\n";
echo "Type of var4 (array): " . gettype($var4) . "\n";
echo "Type of var5 (boolean): " . gettype($var5) . "\n";
echo "Type of var6 (NULL): " . gettype($var6) . "\n";
?>
输出结果:
Type of var1 (string): string
Type of var2 (integer): integer
Type of var3 (float): float
Type of var4 (array): array
Type of var5 (boolean): boolean
Type of var6 (NULL): NULL
在这个示例中,我们声明了六个不同类型的变量,并使用 gettype()
函数分别获取它们的类型。然后我们将每个变量的类型输出到屏幕上。