php method to convert boolean to string: 1. Add the target type "(string)" enclosed in parentheses before the boolean type variable, the syntax is "(string)$bool"; 2. Use strval() function, syntax "strval($bool)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you want to There are many ways to convert boolean type to string type. Here are two methods:
Add the target type enclosed in parentheses before the variable (string )
Use strval() function
Example:
<?php header("Content-type:text/html;charset=utf-8"); $bool1=true; $bool2=false; echo '变量 $bool1 的类型为:'.gettype($bool1).'<br>'; echo '变量 $bool2 的类型为:'.gettype($bool2).'<br><br>'; $str1=(string)$bool1; echo '变量 $str1 的类型为:'.gettype($str1).'<br>'; $str2=strval($bool2); echo '变量 $str2 的类型为:'.gettype($str2).'<br>'; ?>
Output result:
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert boolean to string in php. For more information, please follow other related articles on the PHP Chinese website!