How to convert flase characters into bool type in php

怪我咯
Release: 2023-03-10 19:32:01
Original
3822 people have browsed it

This article summarizes and introduces some situations when converting to Boolean (bool) type in PHP. It is very simple. Friends in need can refer to the following

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

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

Conclusion: When

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

1. Integer type 0

2. Empty String

3. Empty Array

4. NULL

Welcome to add. ..

Test code:

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

The above is the detailed content of How to convert flase characters into bool type in php. For more information, please follow other related articles on the PHP Chinese website!

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!