3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function period_to_timestamps($period) { switch($period) { case "last_7_days": $start = strtotime('-7 days'); $end = strtotime('now'); break; case "this_month": $start = strtotime('first day of this month'); $end = strtotime('now'); break; case "last_month": $start = strtotime('first day of last month'); $end = strtotime('last day of last month'); break; case "this_year": $start = strtotime('01-01-' . date('Y', strtotime('now'))); $end = strtotime('now'); break; case "last_year": $start = strtotime('01-01-' . date('Y', strtotime('now -1 year'))); $end = strtotime('12-31-' . date('Y', strtotime('now -1 year'))); break; default: $start = strtotime('now'); $end = strtotime('now'); } return array(date('m-d-Y', $start), date('m-d-Y', $end); } var_dump(period_to_timestamps('last_7_days')); var_dump(period_to_timestamps('this_month')); var_dump(period_to_timestamps('last_month')); var_dump(period_to_timestamps('this_year')); var_dump(period_to_timestamps('last_year'));
Output for 5.3.0 - 5.4.29
Parse error: syntax error, unexpected ';', expecting ')' in /in/B3pYJ on line 30
Process exited with code 255.