A brief discussion on converting other types into Bool type in PHP, a brief discussion on bool_PHP tutorial

WBOY
Release: 2016-07-12 08:55:06
Original
1209 people have browsed it

A brief discussion on the conversion of other types into Bool types in PHP, a brief discussion on bool

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

Articles you may be interested in:

  • "The Quickest to Understand PHP Programming" Lecture 2 Numbers, Floating Points, Boolean Types, Strings and Arrays
  • Common PHP curl Error: SSL error, bool(false)
  • Introduction to Boolean data type in PHP
  • Detailed explanation of boolean (Boolean) type in php

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117095.htmlTechArticleA brief discussion on the conversion of other types into Bool types in PHP, a brief discussion on bool The cause of the problem: if(true= in PHP =2) Will it return true or false? The result is true. Following this question, I put other data classes in php...
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