<legend id='1qYWk'><style id='1qYWk'><dir id='1qYWk'><q id='1qYWk'></q></dir></style></legend>

      • <bdo id='1qYWk'></bdo><ul id='1qYWk'></ul>
      <tfoot id='1qYWk'></tfoot>

      <small id='1qYWk'></small><noframes id='1qYWk'>

        <i id='1qYWk'><tr id='1qYWk'><dt id='1qYWk'><q id='1qYWk'><span id='1qYWk'><b id='1qYWk'><form id='1qYWk'><ins id='1qYWk'></ins><ul id='1qYWk'></ul><sub id='1qYWk'></sub></form><legend id='1qYWk'></legend><bdo id='1qYWk'><pre id='1qYWk'><center id='1qYWk'></center></pre></bdo></b><th id='1qYWk'></th></span></q></dt></tr></i><div id='1qYWk'><tfoot id='1qYWk'></tfoot><dl id='1qYWk'><fieldset id='1qYWk'></fieldset></dl></div>

      1. PHP 中的 Null 与 False 与 0

        时间:2023-10-15
          <tbody id='crNZT'></tbody>

        <small id='crNZT'></small><noframes id='crNZT'>

            1. <tfoot id='crNZT'></tfoot>

                  <bdo id='crNZT'></bdo><ul id='crNZT'></ul>
                  <legend id='crNZT'><style id='crNZT'><dir id='crNZT'><q id='crNZT'></q></dir></style></legend>

                  <i id='crNZT'><tr id='crNZT'><dt id='crNZT'><q id='crNZT'><span id='crNZT'><b id='crNZT'><form id='crNZT'><ins id='crNZT'></ins><ul id='crNZT'></ul><sub id='crNZT'></sub></form><legend id='crNZT'></legend><bdo id='crNZT'><pre id='crNZT'><center id='crNZT'></center></pre></bdo></b><th id='crNZT'></th></span></q></dt></tr></i><div id='crNZT'><tfoot id='crNZT'></tfoot><dl id='crNZT'><fieldset id='crNZT'></fieldset></dl></div>
                  本文介绍了PHP 中的 Null 与 False 与 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有人告诉我,优秀的开发人员可以发现/利用 NullFalse0 以及所有其他好的无"之间的区别实体.
                  有什么区别,特别是在 PHP 中?和===有关系吗?

                  I am told that good developers can spot/utilize the difference between Null and False and 0 and all the other good "nothing" entities.
                  What is the difference, specifically in PHP? Does it have something to do with ===?

                  推荐答案

                  它是特定于语言的,但在 PHP 中:

                  Null 表示没有".var 尚未初始化.

                  It's language specific, but in PHP :

                  Null means "nothing". The var has not been initialized.

                  False 表示在布尔上下文中不为真".用于明确表明您正在处理逻辑问题.

                  False means "not true in a boolean context". Used to explicitly show you are dealing with logical issues.

                  0 是一个 int.与上面的其余部分无关,用于数学.

                  0 is an int. Nothing to do with the rest above, used for mathematics.

                  现在,棘手的是,在像 PHP 这样的动态语言中,它们在布尔上下文中都有一个值,(在 PHP 中)是 False.

                  Now, what is tricky, it's that in dynamic languages like PHP, all of them have a value in a boolean context, which (in PHP) is False.

                  如果你用 == 测试它,它正在测试布尔值,所以你会得到相等.如果你用====测试它,它会测试类型,你会得到不等式.

                  If you test it with ==, it's testing the boolean value, so you will get equality. If you test it with ===, it will test the type, and you will get inequality.

                  好吧,看看 strrpos() 函数.如果没有找到任何东西,则返回 False,如果在字符串的开头找到了一些东西,则返回 0!

                  Well, look at the strrpos() function. It returns False if it did not found anything, but 0 if it has found something at the beginning of the string !

                  <?php
                  // pitfall :
                  if (strrpos("Hello World", "Hello")) { 
                      // never exectuted
                  }
                  
                  // smart move :
                  if (strrpos("Hello World", "Hello") !== False) {
                      // that works !
                  }
                  ?>
                  

                  当然,如果你处理状态:

                  And of course, if you deal with states:

                  您想区分 DebugMode = False(设置为关闭)、DebugMode = True(设置为打开)和 DebugMode = Null(根本不设置,会导致调试困难;-)).

                  You want to make a difference between DebugMode = False (set to off), DebugMode = True (set to on) and DebugMode = Null (not set at all, will lead to hard debugging ;-)).

                  这篇关于PHP 中的 Null 与 False 与 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                • <tfoot id='DhyVi'></tfoot>

                  <small id='DhyVi'></small><noframes id='DhyVi'>

                  <legend id='DhyVi'><style id='DhyVi'><dir id='DhyVi'><q id='DhyVi'></q></dir></style></legend>

                  <i id='DhyVi'><tr id='DhyVi'><dt id='DhyVi'><q id='DhyVi'><span id='DhyVi'><b id='DhyVi'><form id='DhyVi'><ins id='DhyVi'></ins><ul id='DhyVi'></ul><sub id='DhyVi'></sub></form><legend id='DhyVi'></legend><bdo id='DhyVi'><pre id='DhyVi'><center id='DhyVi'></center></pre></bdo></b><th id='DhyVi'></th></span></q></dt></tr></i><div id='DhyVi'><tfoot id='DhyVi'></tfoot><dl id='DhyVi'><fieldset id='DhyVi'></fieldset></dl></div>

                        <tbody id='DhyVi'></tbody>

                          <bdo id='DhyVi'></bdo><ul id='DhyVi'></ul>