PHP bool false with value 0

Source: Internet
Author: User
PHP bool false and numeric 0

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


PHP is a loose-type language, which means that the Boolean value false and the integer value 0 are treated the same (even C also treats 0 and false as equivalent). You can use the script to determine the equivalence between 0 and Boolean? 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 and the integer value 0 are obviously different.

?

?

PHP has a GetType () function that gets the type of the variable. You can use the = = = Operator (bullish, with three equals). The difference between the and = = operators is that the operator compares both the value and the type of the data .

?

When the termination condition involves different variable types, use the. = = = and?! The = = operator is important for strong type checking.

?

  • Related Article

    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.