温馨提示×

PHP中gettype示例

PHP
小樊
81
2024-12-02 14:11:44
栏目: 编程语言

在PHP中,gettype()函数用于返回变量的类型

<?php
$var1 = "Hello, World!";
$var2 = 42;
$var3 = 3.14;
$var4 = array(1, 2, 3);
$var5 = true;

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";
?>

输出结果:

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

这个示例展示了如何使用gettype()函数来获取不同类型变量的类型信息。

0