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

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

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

      1. PHP foreach 只返回键

        时间:2023-09-21
        <i id='RW2iP'><tr id='RW2iP'><dt id='RW2iP'><q id='RW2iP'><span id='RW2iP'><b id='RW2iP'><form id='RW2iP'><ins id='RW2iP'></ins><ul id='RW2iP'></ul><sub id='RW2iP'></sub></form><legend id='RW2iP'></legend><bdo id='RW2iP'><pre id='RW2iP'><center id='RW2iP'></center></pre></bdo></b><th id='RW2iP'></th></span></q></dt></tr></i><div id='RW2iP'><tfoot id='RW2iP'></tfoot><dl id='RW2iP'><fieldset id='RW2iP'></fieldset></dl></div>

          • <small id='RW2iP'></small><noframes id='RW2iP'>

              • <bdo id='RW2iP'></bdo><ul id='RW2iP'></ul>
                  <tbody id='RW2iP'></tbody>
                <tfoot id='RW2iP'></tfoot>
                1. <legend id='RW2iP'><style id='RW2iP'><dir id='RW2iP'><q id='RW2iP'></q></dir></style></legend>
                  本文介绍了PHP foreach 只返回键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  可能没有任何意义但仍然可能有一个聪明的答案的理论问题.

                  Theoretical question that perhaps does not make any sense but still, maybe there is a clever answer.

                  我想遍历数组并获取它的键和带有它们的东西.我所做的一个简单的例子:

                  I want to iterate through array and get its keys and to something with them. A quick example of what I do:

                  foreach($array as $key => $value) {
                      $other_array[$key] = 'something';
                  }
                  

                  现在,PHP Mess Detector 尖叫着 $value 在此范围内未使用.因此,我在想,这可能不是访问我的 arraykeys 的最佳方式.

                  Now, PHP Mess Detector screams that $value is unused in this scope. Therefore I was thinking that perhaps this is not the best way to access keys of my array.

                  知道如何在不不必要地从我的 array 中取出 values 的情况下做到这一点吗?它是否有任何显着的性能影响......或者我可能只是偏执,应该继续而不用浪费任何人的时间来回答愚蠢的问题:)

                  Any idea how to do it without unnecessarily taking out values out of my array? Does it have any significant performance impact ... or perhaps I am just being paranoid and should carry on without wasting anyone's time with stupid questions :).

                  推荐答案

                  你可以这样做

                  foreach(array_keys($array) as $key) {
                   // do your stuff
                  }
                  

                  这将使 foreach 迭代由数组中的键而不是实际数组组成的数组.请注意,从性能的角度来看,它可能不会更好.

                  That would make the foreach iterate over an array consisting of the keys from your array instead of the actual array. Note that it's probably not better from a performance standpoint though.

                  这篇关于PHP foreach 只返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP - foreach 循环中变量前的 & 下一篇:如何将两个 foreach 循环合二为一

                  相关文章

                  最新文章

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

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

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

                      <tfoot id='ZiRfV'></tfoot>