What is automatic conversion and forced conversion between PHP data types? Are you an expert or a "novice"? Let's discuss the fun of forced conversion and automatic conversion! ! !
Automatic type conversion of Boolean values:
#1: Integer 0 is false, other integer The values are all true
2: Floating point 0.0, the Boolean value is false, as long as there is a non-zero value after the decimal point, it is true;
3: The empty string is false, as long as If there is a space in it, it is considered true;
4: 0 in the string is also considered false, and everything else is true;
For example, the code is as follows:
<?php $bool = 0.6; if($bool){ echo '欢迎来到PHP中文网'; }else{ echo'PHP中文网欢迎你的到来'; } ?>
The running results are as follows:
#1: The integer 0 is false, and the other integer values are all true. The code demonstration is as shown in the figure :
<?php $bool = 0; if($bool){ echo '欢迎来到PHP中文网'; }else{ echo'PHP中文网欢迎你的到来'; } ?>
The running result is as follows:
2: The empty string is false, as long as there is a space in it, it will be counted True; the code demonstration is as shown in the figure:
<?php $str = ''; if($str){ echo '欢迎来到PHP中文网'; }else{ echo'PHP中文网欢迎你的到来'; } ?>
The running result is as follows:
3: 0 of the string, It is also regarded as false, and everything else is true; the code demonstration is as shown in the figure:
<?php $str = '1'; if($str){ echo '欢迎来到PHP中文网'; }else{ echo'PHP中文网欢迎你的到来'; } ?>
The running result is as follows:
Recommended: "PHP Video Tutorial"
The above is the detailed content of Do you know what automatic conversion and forced conversion between PHP data types are? (Source code attached). For more information, please follow other related articles on the PHP Chinese website!