类型强制转换

PHP 中的类型强制转换和 C 中的非常像:在要转换的变量之前加上用括号括起来的目标类型:

<?php
$foo = 10;		// $foo 为整型
$bar = (boolean) $foo;	// $bar 为布尔型
?>

允许的强制转换有:

  1. (int)或(integer) - 转换成整型
  2. (bool)或(boolean) - 转换成布尔型
  3. (float)或(double)或(real) - 转换成浮点型
  4. (string) - 转换成字符串
  5. (array) - 转换成数组
  6. (objec...