1. 基本数据类型:
整型 int / integer、浮点型 float / double、布尔型 bool / boolean、字符串 string、空值 null。
2. 复合数据类型:
数组 array、对象 object、可调用类型 callable、迭代器 iterator。
3. 特殊数据类型:
资源 resource、类名称 class、回调类型 callback / callable。
4. 伪类型:
混合类型 mixed、数值类型 number、回调类型 callback / callable、数组或对象 array|object、void类型 void。
示例代码:
function foo(mixed $arg): void {
if (is_string($arg)) {
echo "字符串类型";
} elseif (is_int($arg)) {
echo "整型类型";
} else {
echo "其他类型";
}
}
foo("hello"); // 输出 "字符串类型"
foo(123); // 输出 "整型类型"
foo(false); // 输出 "其他类型"