解决方案 »

  1.   

    foreach($array as $v){
       $days[]=date("Ymd",strtotime($v['day']));
       $ar[date("Ymd",strtotime($v['day']))]=$v;
    }   
    $arr= range(min($days),max($days));
    $max = max($arr);
    foreach($arr as $v){
        $d = $max-$v;
        if(isset($ar[$v])){
         $tt[$v]['day']=$ar[$v]['day'];
     $tt[$v]['count']=$ar[$v]['count'];
     for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i];
    }else{
         $tt[$v]['day']=date("Y-m-j",strtotime($v));
     $tt[$v]['count']=0;
     for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0;
    }
    }
    print_r(array_values($tt));
      

  2.   

    修改了一下,这个应该可以了。注意php版本至少要5.3.0或以上才能用。
    foreach($array as $v){
       $days[]=date("Ymd",strtotime($v['day']));
       $ar[date("Ymd",strtotime($v['day']))]=$v;
    }   $p = new DatePeriod(
         new DateTime(min($days)),
         new DateInterval('P1D'),
         new DateTime(max($days))
    );
    foreach ($p as $d) {
        $arr[] = $d->format('Ymd');
    }
    $arr[]=max($days);$c = count($arr);
    foreach($arr as $k=>$v){
        $d = $c-$k-1;
        if(isset($ar[$v])){
             $tt[$v]['day']=$ar[$v]['day'];
             $tt[$v]['count']=$ar[$v]['count'];
             for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=(int)$ar[$v]['day_'.$i];
        }else{
             $tt[$v]['day']=date("Y-m-j",strtotime($v));
             $tt[$v]['count']=0;
             for($i=1;$i<=$d;$i++) $tt[$v]['day_'.$i]=0;
        }
    }
    print_r(array_values($tt));