码迷,mamicode.com
首页 > Web开发 > 详细

字符串0.在php和js中转换为布尔类型 值是false还是true

时间:2015-09-24 16:21:59      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

在php 中

$a = ‘0‘;

$b = (bool)$a;

var_dump($a);//输出false

 

 在js中官方说明:

Note:If the value parameter is omitted, or is 0, -0, null, , false, undefined, or NaN, the object is set to false.

 Otherwise it is set to true (even with the string false)!  

测试:  

<script type="text/javascript">    

   var a=‘0‘;      

   if(a){       

     alert(1);      

  }else{             

    alert(0);       

  }

 </script>  值为true。

 

php面试题

原文:转载至http://www.thinkphp.cn/topic/30726.html

字符串0.在php和js中转换为布尔类型 值是false还是true

标签:

原文地址:http://www.cnblogs.com/wqy61/p/4835221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!