loops - Handling month in switch case PHP -


i want current month , add next 3 months , show in table header.

the code have is:

    $mon = (date('m'));      switch($mon) {     case 'mar' :       echo  '<th>mar</th>';     echo  '<th>apr</th>';     echo  '<th>may</th>';     break;     case 'apr' :       echo  '<th>apr</th>';     echo  '<th>may</th>';     echo  '<th>jun</th>';     break;     }      ............... , on .............. 

the above switch case job twelve months. there way dynamically single switch case twelve months rather having 12 switch cases? running mad?

thanks, kimz

you calculate next months on own:

$now = time(); $currentmonth = date('n', $now); $year = date('y', $now); $nextmonth = $currentmonth + 1; $secondnextmonth = $currentmonth + 2;  echo  '<th>' . date('m', $now) . '</th>'; echo  '<th>' . date('m', mktime(0, 0, 0, $nextmonth, 1, $year)) . '</th>'; echo  '<th>' . date('m', mktime(0, 0, 0, $secondnextmonth, 1, $year)) . '</th>'; 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -