php - Add missing dates to an array -


i have following array:

array ( [2010-10-30] => 1 [2010-11-11] => 1 [2010-11-13] => 11 ) 

i trying fill in array missing dates between first , last elements. attempting using following got nowhere:

foreach($users_by_date $key => $value){     $real_next_day = date($key, time()+86400);     $array_next_day = key(next($users_by_date));     if($real_next_day != $array_next_day){       $users_by_date[$real_next_day] = $value;     } } 

the datetime, dateinterval , dateperiod classes can out here.

$begin=date_create('2010-10-30'); $end=date_create('2010-11-13'); $i = new dateinterval('p1d'); $period=new dateperiod($begin,$i,$end);  foreach ($period $d){   $day=$d->format('y-m-d');   $usercount= isset($users_by_date[$day]) ? $users_by_date[$day] :0;   echo "$day $usercount";  } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -