weeks = $ [ ' Sunday ' , ' Monday ' , ' Tuesday ' , ' Wednesday ' , ' Thursday ' , ' Friday ' , ' Saturday ' ]; $ a dates = [ ' statistics_date <= ' => DATE ( " Ymd " , strtotime ( " -1 Day " )), ' statistics_date> = ' =>date("Y-m-d", strtotime ( " -7 Day " )) ]; $ RES = Array (); // last 7 days to produce the array for (I $ = . 7 , $ J = 0 ; $ I> 0 ; $ I -, $ J ++ ) { $ Time = DATE ( " Ymd " , strtotime ( " - " $ I.. " Day " )); $ List [$ Time] = $ J; } // last 7 days week converted to the foreach ($ List aS Key = $> $ Val) { $ D= date("w",strtotime($key)); $w = $weeks[$d]; $res[$w]=$w; }