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

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

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

      1. 在不引用键的情况下访问数组

        时间:2023-06-24

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

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

                    <tbody id='The38'></tbody>
                • 本文介绍了在不引用键的情况下访问数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以使用 $array[key]$array['key']

                  是否有理由避免使用一种而不是另一种?

                  Is there a reason to avoid using one over the other?

                  推荐答案

                  使用后一种变体 $array['key'].前者只会工作,因为 PHP 是宽容的,如果没有名为 key 的常量,则假定字符串值 key:

                  Use the latter variant $array['key']. The former will only work because PHP is tolerant and assumes the string value key if there is no constant named key:

                  始终在字符串文字数组索引周围使用引号.例如, $foo['bar'] 是正确的,而 $foo[bar] 则不是.[...] 这是错误的,但它有效.原因是这个 […] 有一个未定义的常量 (bar) 而不是字符串 ('bar' - 注意引号).

                  Always use quotes around a string literal array index. For example, $foo['bar'] is correct, while $foo[bar] is not. […] This is wrong, but it works. The reason is that this […] has an undefined constant (bar) rather than a string ('bar' - notice the quotes).

                  另见数组做和不做.

                  现在与在普通 PHP 代码中访问数组相反,当使用 双引号字符串中的变量解析 您实际上需要在不带引号的情况下编写它或使用 花括号语法:

                  Now in opposite to accessing arrays in plain PHP code, when using variable parsing in double quoted strings you actually need to write it without quotes or use the curly brace syntax:

                  [...] 在双引号字符串中,数组索引不包含引号是有效的,所以 "$foo[bar]" 是有效的.有关原因的详细信息以及有关字符串中变量解析的部分,请参见上述示例.

                  […] inside a double-quoted string, it's valid to not surround array indexes with quotes so "$foo[bar]" is valid. See the above examples for details on why as well as the section on variable parsing in strings.

                  所以:

                  // syntax error
                  echo "$array['key']";
                  
                  // valid
                  echo "$array[key]";
                  echo "{$array['key']}";
                  

                  这篇关于在不引用键的情况下访问数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“&lt;&lt;&lt;"的名字是什么?操作员? 下一篇:我在哪里可以阅读有关使用“?"完成的条件的信息?和“:"(冒号)?

                  相关文章

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

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