Home > Backend Development > PHP Tutorial > A brief discussion on converting other types into Bool type in PHP_php skills

A brief discussion on converting other types into Bool type in PHP_php skills

WBOY
Release: 2016-05-16 19:55:44
Original
1083 people have browsed it

The origin of the problem: Will if(true==2) in PHP return true or false?

The result is true. Following this question, I will also test other data types of PHP.

Conclusion:

When converted to bool type, several types of data will become false:

1.Integer type 0

2. Empty string

3. Empty array

4.NULL

Additions are welcome...

Test code:

<&#63;php
function p($title,$mybool){
  echo "<pre class="brush:php;toolbar:false">".$title;
  echo var_dump($mybool)."
"; } class foo { function do_foo() { echo "你好!"; } } echo"
PHP中的其他类型转化为Bool类型
"; //零 $n0=boolval(0); p("零:",$n0); //正整数 $n=boolval(2); p("正整数:",$n); //负整数 $nx=boolval(-2); p("负整数:",$nx); //字符空格 $ss=boolval(" "); p("字符空格:",$ss); //空字符串 $sn=boolval(""); p("空字符串:",$sn); //字符串 $s=boolval("chinacion"); p("字符串:",$s); //空数组 $an=boolval(array()); p("空数组:",$an); //数组 $a=boolval(array(0=>1)); p("数组:",$a); //null类型 $nu = boolval(NULL); p("NULL:",$nu); //object $bar = new foo; $bar; $obj = boolval($bar); p("Object:",$obj);
Copy after login

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