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('first day of last year'); $end = strtotime('last day of last year'); break; default: $start = strtotime('now'); $end = strtotime('now'); } return array($start, $end); } var_dump(period_to_timestamps('last_7_days'));
Output for 4.3.0 - 4.4.9, 5.0.3 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
array(2) { [0]=> int(1403030491) [1]=> int(1403635291) }
Output for 5.0.0 - 5.0.2
array(2) { [0]=> int(1402956000) [1]=> int(1403560800) }