<bdo id='2m0GK'></bdo><ul id='2m0GK'></ul>
    <legend id='2m0GK'><style id='2m0GK'><dir id='2m0GK'><q id='2m0GK'></q></dir></style></legend>

    <small id='2m0GK'></small><noframes id='2m0GK'>

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

        <tfoot id='2m0GK'></tfoot>

        如何使用 PHP 在 foreach 循环中对行进行分页

        How to Paginate lines in a foreach loop with PHP(如何使用 PHP 在 foreach 循环中对行进行分页)

        <small id='4XBFL'></small><noframes id='4XBFL'>

          <tbody id='4XBFL'></tbody>

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

            <tfoot id='4XBFL'></tfoot>
                  本文介绍了如何使用 PHP 在 foreach 循环中对行进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用以下代码显示我的 Twitter 个人资料中的朋友列表.我想一次只加载一个特定的数字,比如 20,然后在底部提供分页链接,第一个 1-2-3-4-5(无论多少除以限制)最后

                  Using the following code to display a list of friends from my twitter profile. Id like to only load a certain number at a time, say 20, then provide pagination links at the bottom for First 1-2-3-4-5(however many divided by limit) Last

                  $xml = simplexml_load_string($rawxml);
                  
                  foreach ($xml->id as $key => $value) 
                  {
                      $profile           = simplexml_load_file("https://twitter.com/users/$value");
                      $friendscreenname  = $profile->{"screen_name"};
                      $profile_image_url = $profile->{"profile_image_url"};
                  
                      echo "<a href=$profile_image_url>$friendscreenname</a><br>";
                  }
                  

                  ******更新******

                  ******update******

                  if (!isset($_GET['i'])) {
                      $i = 0;
                  } else {
                      $i = (int) $_GET['i'];
                  }
                  
                  $limit  = $i + 10;
                  $rawxml = OauthGetFriends($consumerkey, $consumersecret, $credarray[0], $credarray[1]);
                  $xml    = simplexml_load_string($rawxml);
                  
                  foreach ($xml->id as $key => $value)
                  {
                  
                      if ($i >= $limit) {
                          break;
                      }
                  
                      $i++;
                      $profile           = simplexml_load_file("https://twitter.com/users/$value");
                      $friendscreenname  = $profile->{"screen_name"};
                      $profile_image_url = $profile->{"profile_image_url"};
                  
                      echo "<a href=$profile_image_url>$friendscreenname</a><br>";
                  }
                  
                  echo "<a href=step3.php?i=$i>Next 10</a><br>";
                  

                  这行得通,只需要偏移从 $i 开始的输出.思考array_slice?

                  This works, just have to offset the output starting at $i. Thinking array_slice?

                  推荐答案

                  一个非常优雅的解决方案是使用 LimitIterator:

                  A very elegant solution is using a LimitIterator:

                  $xml = simplexml_load_string($rawxml);
                  // can be combined into one line
                  $ids = $xml->xpath('id'); // we have an array here
                  $idIterator = new ArrayIterator($ids);
                  $limitIterator = new LimitIterator($idIterator, $offset, $count);
                  foreach($limitIterator as $value) {
                      // ...
                  }
                  
                  // or more concise
                  $xml = simplexml_load_string($rawxml);
                  $ids = new LimitIterator(new ArrayIterator($xml->xpath('id')), $offset, $count);
                  foreach($ids as $value) {
                      // ...
                  }
                  

                  这篇关于如何使用 PHP 在 foreach 循环中对行进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

                  <small id='2KTfy'></small><noframes id='2KTfy'>

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

                            <bdo id='2KTfy'></bdo><ul id='2KTfy'></ul>

                              <tbody id='2KTfy'></tbody>

                            <legend id='2KTfy'><style id='2KTfy'><dir id='2KTfy'><q id='2KTfy'></q></dir></style></legend>
                          • <tfoot id='2KTfy'></tfoot>