Phpboolfalse and value 0

Source: Internet
Author: User
Convert phpboolfalse to 0: home. phpchina. comspace. php? Uid108724 & amp; doblog & amp; id54899PHP is a loose language, which means that the Boolean value false and integer value 0 are treated as the same (even c regards 0 and false as the equivalent value ). You can use the script to determine 0 and php bool false and the value 0.

Turn: http://home.phpchina.com/space.php? Uid = 108724 & do = blog & id = 54899


PHP is a loose language, which means that Boolean values false and integer values 0 are considered the same (even c treats 0 and false as equivalent ). Can I use a script to determine the values of 0 and boolean? The equivalence of false:

?

? $ Test_var = 0;
? If ($ test_var = false ){
?? Echo "yes ";
?} Else {
?? Echo "no ";
?}
?>?

?

Output: yes

?

_________________________________________________________________________________

?

? $ Test_var = 0;
? If ($ test_var! = False ){
?? Echo "yes ";
?} Else {
?? Echo "no ";
?}
?>

?

Output: yes

?

_________________________________________________________________

?

The problem is that the Boolean value false is obviously different from the integer value 0.

?

?

PHP has a gettype () function to obtain the variable type. You can use the = operator (after reading it, there are three equal signs ). The difference between the = operator and the = operator is that the operator is bothCompare data values and types.

?

When different variable types are involved in the conditions for termination, use? ===And ?! = It is very important to perform a strong type check for operators.

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.