反了解决方法

Jun 13, 2016 am 10:23 AM
empty false quot true var

反了

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$a = 0;function test($a){    if($a==''){        return true;    }else{        return false;    }}
Copy after login


这个函数为什么反回true呢

------解决方案--------------------
var_dump($a==''); 返回什么
------解决方案--------------------
∵ $a = 0 等于空
∴ $a == '' 成立

$a === '' 就不成立了
------解决方案--------------------
0,false,‘’这三个都是 == 的,你可以用 === 来判断。
------解决方案--------------------
PHP code
0 == null == false == '' == ""当然全等都不成立,暂时就想到这么多<br><font color="#e78608">------解决方案--------------------</font><br>參考php手冊的empty函數,和這差不多。<br>bool empty ( mixed var )<br>如果 var 是非空或非零的值,则 empty() 返回 FALSE。换句话说,""、0、"0"、NULL、FALSE、array()、var $var; 以及没有任何属性的对象都将被认为是空的,如果 var 为空,则返回 TRUE。  <br><br><br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
引用:

∵ $a = 0 等于空
∴ $a == '' 成立

$a === '' 就不成立了

== 和===有啥区别
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP determines whether a specified key exists in an array PHP determines whether a specified key exists in an array Mar 21, 2024 pm 09:21 PM

PHP determines whether a specified key exists in an array

The role and examples of var keyword in PHP The role and examples of var keyword in PHP Jun 28, 2023 pm 08:58 PM

The role and examples of var keyword in PHP

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

18 Ways to Fix Audio Service Not Responding Issue on Windows 11

Let's talk about the differences between var, let and const (code example) Let's talk about the differences between var, let and const (code example) Jan 06, 2023 pm 04:25 PM

Let's talk about the differences between var, let and const (code example)

PHP function introduction—empty(): Check whether the variable is empty PHP function introduction—empty(): Check whether the variable is empty Jul 25, 2023 am 10:23 AM

PHP function introduction—empty(): Check whether the variable is empty

Solution to the error AttributeError(\'{0!r} object has no attribute {1!r}\'.format(type(self).__name__, k)) Solution to the error AttributeError(\'{0!r} object has no attribute {1!r}\'.format(type(self).__name__, k)) Feb 29, 2024 pm 06:40 PM

Solution to the error AttributeError(\'{0!r} object has no attribute {1!r}\'.format(type(self).__name__, k))

Detailed explanation of the meaning of true in PHP functions Detailed explanation of the meaning of true in PHP functions Mar 16, 2024 am 08:57 AM

Detailed explanation of the meaning of true in PHP functions

See all articles