search

Home  >  Q&A  >  body text

php实现关于这样数组的办法 求大神支招

{

"jwc_grades": {

        "2011": {

                    {

               }
          }
         "2012": {

                    {

                  }
          }
         "2013": {

                    {

                 }
           }
        "2014": {

                    {

                }
           }
    }
}
怎样用for循环实现上面的数组  其中2011等数字是变量
巴扎黑巴扎黑2902 days ago392

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-10 15:12:20

    这是在写教务系统么...

    $jwc_grades = array();
    $fromYear = 2011;
    $toYear = (int)date("Y");
    for($year = $fromYear; $year<=$toYear; $year++) {
        $jwc_grades[$year] = array();
        //do whatever u want...
    }
    $arr = compact('jwc_grades');
    print_r( json_encode($arr) );
    

    reply
    0
  • Cancelreply