Home > php教程 > php手册 > body text

php中Null 空 与0值区别分析

WBOY
Release: 2016-05-25 16:45:55
Original
1522 people have browsed it

下面来给大家介绍一个可能大家都常用模糊的php中Null 空 与0值区别分析,下面举了几个例子,大家仔细的看看吧.

PHP实例代码如下:

<?php
$test = 0;
if ($test == &#39;&#39;) {
    echo &#39;<br />在php中,0即为空&#39;; //被输出
    
}
if ($test === &#39;&#39;) {
    echo &#39;<br />在php中,0即为空&#39;; //不被输出
    
}
if ($test == NULL) {
    echo &#39;<br />在php中,0即为空&#39;; //被输出
    
}
if ($test === NULL) {
    echo &#39;<br />在php中,0即为空&#39;; //不被输出
    
}
if ($test == false) {
    echo &#39;<br />在php中,0即为空&#39;; //被输出
    
}
if ($test === false) {
    echo &#39;<br />在php中,0即为空&#39;; //不被输出
    
}
?>
Copy after login

从上面看得出来当为空时就与0或null是相等了,但如果是精确比较时我们会发现0与空或null是以字符对比了这样就不会了,如果是普通对比他就是逻辑假来对比了,从这里我们可以看出0==false,null=false,''==false.


教程链接:

随意转载~但请保留教程地址★

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!