PHP 类型转换

1
2
3
4
<?php
$foo = 10; // $foo 是 int
$bar = (bool) $foo; // $bar 是 bool
?>

(int) ——转换为 int
(bool) ——转换为 bool
(float) ——转换为 float
(string) ——转换为 string
(array) ——转换为 array
(object) ——转换为 object
(unset) ——转换为 NULL

隐式转换