<tfoot id='Jt12H'></tfoot>

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

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

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

        在 PHP 中使用 foreach 循环时查找数组的最后一个元

        时间:2023-09-22
      1. <legend id='Nc6bP'><style id='Nc6bP'><dir id='Nc6bP'><q id='Nc6bP'></q></dir></style></legend>
            <bdo id='Nc6bP'></bdo><ul id='Nc6bP'></ul>
            <tfoot id='Nc6bP'></tfoot>

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

                    <tbody id='Nc6bP'></tbody>
                1. <i id='Nc6bP'><tr id='Nc6bP'><dt id='Nc6bP'><q id='Nc6bP'><span id='Nc6bP'><b id='Nc6bP'><form id='Nc6bP'><ins id='Nc6bP'></ins><ul id='Nc6bP'></ul><sub id='Nc6bP'></sub></form><legend id='Nc6bP'></legend><bdo id='Nc6bP'><pre id='Nc6bP'><center id='Nc6bP'></center></pre></bdo></b><th id='Nc6bP'></th></span></q></dt></tr></i><div id='Nc6bP'><tfoot id='Nc6bP'></tfoot><dl id='Nc6bP'><fieldset id='Nc6bP'></fieldset></dl></div>
                2. 本文介绍了在 PHP 中使用 foreach 循环时查找数组的最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用一些参数编写 SQL 查询创建器.在 Java 中,只需通过数组长度检查当前数组位置,就可以很容易地从 for 循环内部检测数组的最后一个元素.

                  I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element of an array from inside the for loop by just checking the current array position with the array length.

                  for(int i=0; i< arr.length;i++){
                       boolean isLastElem = i== (arr.length -1) ? true : false;        
                  }
                  

                  在 PHP 中,它们有非整数索引来访问数组.因此,您必须使用 foreach 循环遍历数组.当您需要做出一些决定(在我的情况下,在构建查询时附加或/和参数)时,这会成为问题.

                  In PHP they have non-integer indexes to access arrays. So you must iterate over an array using a foreach loop. This becomes problematic when you need to take some decision (in my case to append or/and parameter while building query).

                  我相信一定有一些标准的方法可以做到这一点.

                  I am sure there must be some standard way of doing this.

                  你如何在 PHP 中解决这个问题?

                  How do you solve this in PHP?

                  推荐答案

                  听起来你想要这样的东西:

                  It sounds like you want something like this:

                  $numItems = count($arr);
                  $i = 0;
                  foreach($arr as $key=>$value) {
                    if(++$i === $numItems) {
                      echo "last index!";
                    }
                  }    
                  

                  话虽如此,您不必在 php 中使用 foreach 迭代数组".

                  That being said, you don't -have- to iterate over an "array" using foreach in php.

                  这篇关于在 PHP 中使用 foreach 循环时查找数组的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP foreach 循环键值 下一篇:在foreach循环php中求和值

                  相关文章

                  最新文章

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

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