Type
PHP 类型与变量函数
判断、转换、调试输出。isset 与 empty 的区别是面试高频,也是线上 bug 高频。
| 函数 | 说明 | 返回 |
|---|---|---|
| empty() | 判断变量是否为「空值」:false、0、0.0、''、'0'、[]、null 都算空。 | bool |
| gettype() | 返回变量的类型名称。 | string |
| intval() | 把变量转成整数,可以指定进制。 | int |
| is_array() | 判断变量是不是数组。 | bool |
| is_numeric() | 判断变量是不是数字或数字字符串。 | bool |
| is_string() | 判断变量是不是字符串。 | bool |
| isset() | 判断变量是否已定义且不为 null。 | bool |
| print_r() | 以人类可读的方式打印变量,数组和对象都能看。 | string|bool |
| settype() | 直接把变量转换成指定类型,改变原变量。 | bool |
| strval() | 把变量转成字符串。 | string |
| var_dump() | 打印变量的类型和值,调试的第一选择。 | void |