1. <small id='uxImm'></small><noframes id='uxImm'>

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

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

        如何将字符串转换为布尔值 php

        时间:2023-07-15

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

            1. <small id='1mt2J'></small><noframes id='1mt2J'>

                <bdo id='1mt2J'></bdo><ul id='1mt2J'></ul>
                    <tbody id='1mt2J'></tbody>
                  本文介绍了如何将字符串转换为布尔值 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将字符串转换为boolean?

                  $string = 'false';
                  
                  $test_mode_mail = settype($string, 'boolean');
                  
                  var_dump($test_mode_mail);
                  
                  if($test_mode_mail) echo 'test mode is on.';
                  

                  它返回,

                  布尔真

                  但它应该是boolean false.

                  推荐答案

                  除非字符串的值被 PHP 视为空"(取自 empty 文档):

                  Strings always evaluate to boolean true unless they have a value that's considered "empty" by PHP (taken from the documentation for empty):

                  1. "" (一个空字符串);
                  2. "0" (0 作为字符串)
                  1. "" (an empty string);
                  2. "0" (0 as a string)

                  如果您需要根据字符串的文本值设置布尔值,则需要检查该值是否存在.

                  If you need to set a boolean based on the text value of a string, then you'll need to check for the presence or otherwise of that value.

                  $test_mode_mail = $string === 'true'? true: false;
                  

                  上面的代码是为了清楚地理解.在实际使用中,下面的代码可能更合适:

                  the above code is intended for clarity of understanding. In actual use the following code may be more appropriate:

                  $test_mode_mail = ($string === 'true');
                  

                  或者使用 filter_var 函数可能会覆盖更多的布尔值:

                  or maybe use of the filter_var function may cover more boolean values:

                  filter_var($string, FILTER_VALIDATE_BOOLEAN);
                  

                  filter_var 涵盖整个范围的值,包括真值 "true", "1", "yes"on".请参阅此处了解更多详情.

                  filter_var covers a whole range of values, including the truthy values "true", "1", "yes" and "on". See here for more details.

                  这篇关于如何将字符串转换为布尔值 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中将整数转换为字符串 下一篇:PHP 字符串浮动

                  相关文章

                    1. <small id='YO6uu'></small><noframes id='YO6uu'>

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

                      <legend id='YO6uu'><style id='YO6uu'><dir id='YO6uu'><q id='YO6uu'></q></dir></style></legend>
                    2. <tfoot id='YO6uu'></tfoot>