3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function closestDate($day_name){ $day = ucfirst($day_name); if(date('l', time()) == $day_name) return date("Y-m-d", time()); else if(abs(time()-strtotime('next '.$day_name)) < abs(time()-strtotime('last '.$day_name))) return date("Y-m-d", strtotime('next '.$day_name)); else return date("Y-m-d", strtotime('last '.$day_name)); } echo closestDate('Friday');
Output for 4.4.0 - 4.4.9, 5.0.5 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2013-11-15
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
2013-11-08