问个弱智的问题

WBOY
Release: 2016-06-23 14:23:54
Original
938 people have browsed it

如何判断空  只要没有内容才返回真  


$str = 0;
!empty($str);  不行啊 


$str = 0;
$str != '';  不行啊


$str = '';
isset($str);  也不行啊

怎么能让它们不把0认为是空啊

我想要的结果是  只要有内容就代表不为空  不管0不0的







回复讨论(解决方案)

strlen($str)===0

试试typeof  var_dump

strlen($str)===0
取长度 三等号 又学了一手 

empty($str) 不就可以了吗?为什么还要求反?

strlen($str)===0

第一个empty(0) php把这当真,第二个$str!==''这样就行了,isset()是判断这个变量存不存在,你设置空变量也是变量啊。

empty可以的

看下这篇文章,总体还挺全面。
http://blog.csdn.net/timecolor/article/details/8762930

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 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!