Conversion of the php-type

Source: Internet
Author: User

Types of conversions
在PHP中变量的类型是可以随时的转变的,非常的灵活最常见的是字符串与数字的转换,或是数字/字符串->到布尔值的转换
Example:
$a = ‘13‘;$a = $a + 2;var_dump($a);输出结果:int 15$a = ‘13.5‘;$a = $a + 2;var_dump($a);输出结果:float 15$a = ‘hello13world‘;$a = $a + 2;var_dump($a);输出结果:int 2//下面例子:字符串连接$a = 123;$a = $a.‘hello‘;var_dump($a);输出结果:string 123hello
PHP Manual:
数字型字符串在参与运算的时候就自动转换成数字了,然后根据具体运算时候的类型而改变成具体类型。运算截取:从左到右截取,直到碰到不合法的数字,截取出来的部分转成数字所以在例子-第三个的时候 一开始就碰到了不合法的字符,所以后面的结果就是整型的2

With respect to the Boolean type, the following value is treated as a Boolean false, while the other is treated as an empty string in the Boolean true string: ' ' integer ' of 0 floating-point type ' 0.0 string ' of ' 0 ' boolean null null-empty array

详细在php手册 empty中有说明

Conversion of the php-type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.