Php 把自动标题放在桌面上

Php 把自动标题放在桌面上,php,Php,我有这段代码,它将生成一个年份表,从2006年到2017年,每个年份分成5个组 如何将标题放在表格顶部,如下例所示 <?php $chunkSize = 5; $starting_year = 2006; $ending_year = date("Y"); //create an array of years $years = range($starting_year,$ending_year); /

我有这段代码,它将生成一个年份表,从2006年到2017年,每个年份分成5个组

如何将标题放在表格顶部,如下例所示

    <?php
      $chunkSize = 5;
      $starting_year  = 2006;
      $ending_year    = date("Y");
      //create an array of years
      $years = range($starting_year,$ending_year); 
      //[2006,2007,....,2016,2017]

      //split years in required size
      $chunked = array_chunk($years,$chunkSize);
      //[ [2006,....,2010], [2011,...2015], [2016,2017]]

      //reverse it
      $reversed = array_reverse($chunked); 
      //[ [2016,2017], [2011,...2015], [2006,....,2010]]


      foreach($reversed as $reverse) {
      echo "<b>Year $year</b>";
         echo "<table class='table table-striped table-bordered'><tbody>";
echo "<tr>";
        foreach($reverse as $year) {
          echo "<th>{$year}</th>";
        }
        echo "</tr><tr>";
        foreach($reverse as $year) {
          $result= $myDB->query("SELECT total FROM ".$myDB->prefix("statistics")." WHERE year='{$year}'") or die(mysql_error());
          echo "<td>{$result['total']}</td>";
        }
        echo "</tr>";
        echo "</tbody></table>";
      }
期望输出

**Year 2016-2017**
2016    2017            
total  total  

**Year 2011 - 2015**      
2011    2012    2013    2014    2015
total  total   total    total  total

**Year 2006 - 2010**
2006    2007    2008    2009    2010
total  total   total    total  total

看看您的代码,简单的解决方案不只是:

echo "<b>Year {$reverse[0]}-{$reverse[count($reverse)-1]}</b>";
echo“年份{$reverse[0]}-{$reverse[count($reverse)-1]}”;

您想输出
$reverse
数组的第一个和最后一个元素。

谢谢。但它不起作用。我得到了一个半加载页面oops,我有
$count
而不是
count
-是我的输入错误吗?是的,再次感谢..现在它起作用了。。我还是个初学者1.你真的帮了我很多忙。祝你今天愉快
echo "<b>Year {$reverse[0]}-{$reverse[count($reverse)-1]}</b>";