3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $m = 1; $y = 2016; echo "Original date Snaps to\n\n"; foreach (range(1, 31) as $day) { if($day <= 9){ $day = '0'.$day; } ///////////////////////////// // this is the important bit $snap = strtotime("monday this week",strtotime("$m/$day/$y")); ///////////////////////////// echo str_pad(date('l',strtotime("$m/$day/$y")), 9, " ", STR_PAD_LEFT)," $m/$day/$y: ",date('r',$snap),"\n"; }
based on 4lPH8
Output for 5.6.23 - 5.6.28, 7.0.8 - 7.2.0
Original date Snaps to Friday 1/01/2016: Mon, 28 Dec 2015 00:00:00 +0100 Saturday 1/02/2016: Mon, 28 Dec 2015 00:00:00 +0100 Sunday 1/03/2016: Mon, 28 Dec 2015 00:00:00 +0100 Monday 1/04/2016: Mon, 04 Jan 2016 00:00:00 +0100 Tuesday 1/05/2016: Mon, 04 Jan 2016 00:00:00 +0100 Wednesday 1/06/2016: Mon, 04 Jan 2016 00:00:00 +0100 Thursday 1/07/2016: Mon, 04 Jan 2016 00:00:00 +0100 Friday 1/08/2016: Mon, 04 Jan 2016 00:00:00 +0100 Saturday 1/09/2016: Mon, 04 Jan 2016 00:00:00 +0100 Sunday 1/10/2016: Mon, 04 Jan 2016 00:00:00 +0100 Monday 1/11/2016: Mon, 11 Jan 2016 00:00:00 +0100 Tuesday 1/12/2016: Mon, 11 Jan 2016 00:00:00 +0100 Wednesday 1/13/2016: Mon, 11 Jan 2016 00:00:00 +0100 Thursday 1/14/2016: Mon, 11 Jan 2016 00:00:00 +0100 Friday 1/15/2016: Mon, 11 Jan 2016 00:00:00 +0100 Saturday 1/16/2016: Mon, 11 Jan 2016 00:00:00 +0100 Sunday 1/17/2016: Mon, 11 Jan 2016 00:00:00 +0100 Monday 1/18/2016: Mon, 18 Jan 2016 00:00:00 +0100 Tuesday 1/19/2016: Mon, 18 Jan 2016 00:00:00 +0100 Wednesday 1/20/2016: Mon, 18 Jan 2016 00:00:00 +0100 Thursday 1/21/2016: Mon, 18 Jan 2016 00:00:00 +0100 Friday 1/22/2016: Mon, 18 Jan 2016 00:00:00 +0100 Saturday 1/23/2016: Mon, 18 Jan 2016 00:00:00 +0100 Sunday 1/24/2016: Mon, 18 Jan 2016 00:00:00 +0100 Monday 1/25/2016: Mon, 25 Jan 2016 00:00:00 +0100 Tuesday 1/26/2016: Mon, 25 Jan 2016 00:00:00 +0100 Wednesday 1/27/2016: Mon, 25 Jan 2016 00:00:00 +0100 Thursday 1/28/2016: Mon, 25 Jan 2016 00:00:00 +0100 Friday 1/29/2016: Mon, 25 Jan 2016 00:00:00 +0100 Saturday 1/30/2016: Mon, 25 Jan 2016 00:00:00 +0100 Sunday 1/31/2016: Mon, 25 Jan 2016 00:00:00 +0100
Output for 5.5.0 - 5.6.22, 7.0.0 - 7.0.7
Original date Snaps to Friday 1/01/2016: Mon, 28 Dec 2015 00:00:00 +0100 Saturday 1/02/2016: Mon, 28 Dec 2015 00:00:00 +0100 Sunday 1/03/2016: Mon, 04 Jan 2016 00:00:00 +0100 Monday 1/04/2016: Mon, 04 Jan 2016 00:00:00 +0100 Tuesday 1/05/2016: Mon, 04 Jan 2016 00:00:00 +0100 Wednesday 1/06/2016: Mon, 04 Jan 2016 00:00:00 +0100 Thursday 1/07/2016: Mon, 04 Jan 2016 00:00:00 +0100 Friday 1/08/2016: Mon, 04 Jan 2016 00:00:00 +0100 Saturday 1/09/2016: Mon, 04 Jan 2016 00:00:00 +0100 Sunday 1/10/2016: Mon, 11 Jan 2016 00:00:00 +0100 Monday 1/11/2016: Mon, 11 Jan 2016 00:00:00 +0100 Tuesday 1/12/2016: Mon, 11 Jan 2016 00:00:00 +0100 Wednesday 1/13/2016: Mon, 11 Jan 2016 00:00:00 +0100 Thursday 1/14/2016: Mon, 11 Jan 2016 00:00:00 +0100 Friday 1/15/2016: Mon, 11 Jan 2016 00:00:00 +0100 Saturday 1/16/2016: Mon, 11 Jan 2016 00:00:00 +0100 Sunday 1/17/2016: Mon, 18 Jan 2016 00:00:00 +0100 Monday 1/18/2016: Mon, 18 Jan 2016 00:00:00 +0100 Tuesday 1/19/2016: Mon, 18 Jan 2016 00:00:00 +0100 Wednesday 1/20/2016: Mon, 18 Jan 2016 00:00:00 +0100 Thursday 1/21/2016: Mon, 18 Jan 2016 00:00:00 +0100 Friday 1/22/2016: Mon, 18 Jan 2016 00:00:00 +0100 Saturday 1/23/2016: Mon, 18 Jan 2016 00:00:00 +0100 Sunday 1/24/2016: Mon, 25 Jan 2016 00:00:00 +0100 Monday 1/25/2016: Mon, 25 Jan 2016 00:00:00 +0100 Tuesday 1/26/2016: Mon, 25 Jan 2016 00:00:00 +0100 Wednesday 1/27/2016: Mon, 25 Jan 2016 00:00:00 +0100 Thursday 1/28/2016: Mon, 25 Jan 2016 00:00:00 +0100 Friday 1/29/2016: Mon, 25 Jan 2016 00:00:00 +0100 Saturday 1/30/2016: Mon, 25 Jan 2016 00:00:00 +0100 Sunday 1/31/2016: Mon, 01 Feb 2016 00:00:00 +0100