Home > Backend Development > PHP Tutorial > php语法问题

php语法问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:18:02
Original
1244 people have browsed it

  • var_dump('89:90' == 89);
    打印出来是true,怎么理解?

回复内容:

  • var_dump('89:90' == 89);
    打印出来是true,怎么理解?

一个字符串和一个整型做比较,这时候,字符串是会被强转成整型的。
<code>var_dump(intval('89:90'));</code> //int 89
所以就是true了

<code>var_dump(intval('89:90'));</code>
Copy after login

你试下这个就知道了 == 是做类型转换后在比较。 === 不做类型转换

这里的两个==会将值进行比较,如果类型不一致会进行自动转换(注:很多人称之为强制转换,不对的,强制转换是int()这样,面试会有坑)

由于php底层语言是c写的,所以转换规则是c语言的转换规则。 char->int->float->double由小到大,不可以反过来。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template