Home > Backend Development > PHP Tutorial > PHP比较mysql里的Int数据

PHP比较mysql里的Int数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:46:06
Original
1259 people have browsed it

比如mysql某个表的某个column是int(10)类型, 我在php里面获取到一条这样的数据,然后我想知道这个数据是不是某个值,我是应该 $data === 2 呢, 还是 $data === "2" ? 我在插入数据的时候是 $data = 2;

回复内容:

比如mysql某个表的某个column是int(10)类型, 我在php里面获取到一条这样的数据,然后我想知道这个数据是不是某个值,我是应该 $data === 2 呢, 还是 $data === "2" ? 我在插入数据的时候是 $data = 2;

MySQL返回的数据有2种(文本或二进制),比较的话,就$data === '2'.

<code>$a == $b    等于  TRUE,如果类型转换后 $a 等于 $b。
$a === $b   全等  TRUE,如果 $a 等于 $b,并且它们的类型也相同。
</code>
Copy after login

既然是整型,就不要打引号了,直接写为 $data == 2 即可。

Related labels:
php
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