• <bdo id='0nKyQ'></bdo><ul id='0nKyQ'></ul>

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

      <small id='0nKyQ'></small><noframes id='0nKyQ'>

        <tfoot id='0nKyQ'></tfoot>

        PHP - 使用 foreach 抓取第一个元素

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

              <tbody id='yifT0'></tbody>

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

            • <bdo id='yifT0'></bdo><ul id='yifT0'></ul>

                <tfoot id='yifT0'></tfoot>
                1. 本文介绍了PHP - 使用 foreach 抓取第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  想知道在 foreach 循环中获得第一次迭代的好方法是什么.我想在第一次迭代中做一些不同的事情.

                  Wondering what would be a good method to get the first iteration on a foreach loop. I want to do something different on the first iteration.

                  在这些情况下,有条件是我们最好的选择吗?

                  Is a conditional our best option on these cases?

                  推荐答案

                  是的,如果您无法以不同的方式(正常的 for 循环)遍历对象,在这种情况下只需使用条件:

                  Yes, if you are not able to go through the object in a different way (a normal for loop), just use a conditional in this case:

                  $first = true;
                  foreach ( $obj as $value )
                  {
                      if ( $first )
                      {
                          // do something
                          $first = false;
                      }
                      else
                      {
                          // do something
                      }
                  
                      // do something
                  }
                  

                  这篇关于PHP - 使用 foreach 抓取第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:计算 foreach 循环中的迭代次数 下一篇:如何在 foreach 循环中获取当前数组索引?

                  相关文章

                  最新文章

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

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

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

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