-
数值类型(Int、Float)和字符类型(Sting)相加(+)时,结果为数值类型。
数值结果取决于字符串的第一部分的字符类型(PHP 支持以类似数组使用下标获取操作字符串)。- 如果是数值类型,则做正常的数学运算;
- 如果不是,该字符串会当作零(0)来处理。
见下面的示例:
<?php $foo = 1 + "bob-1.3e3"; // $foo is integer (1) $foo = 1 + "10 Small Pigs"; // $foo is integer (11) $foo = "10.0 pigs " + 1.0; // $foo is float (11) $foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2) ?>
-
将一个变量转换为null类型的方法:
(unset) - 转换为 NULL (PHP 5)
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme