Custom week range in PHP

easy solution web : OOPS in PHP

How to get create customized  week range in PHP

Here we have created a week range from Saturday to Friday by passing any date of the month and the day from which we need to start our week.

<?php
echo "<pre>".print_r(monthArr("05-03-2018","Saturday"),true);
function monthArr($date,$startDay){
$date = strtotime($date);
$date = "01-".date("m",$date)."-".date("Y",$date);
$firstDateOfCustomWeek = date("d-m-Y",strtotime("next ".$startDay, date(strtotime($date))));
$lastDayOfMonth = date("d-m-Y",(strtotime("+1 month", date(strtotime($date)))-1));
$arr = array();
$count = strtotime($firstDateOfCustomWeek);
while($count < strtotime($lastDayOfMonth." 23:59:59")){
$arr[] =  array(date("d-m-Y",$count),date("d-m-Y",strtotime("+6 days",date($count))));
$count =  strtotime("+7 days",date($count));
}
return $arr;
}
?>

Output

Array
(
[0] => Array
(
[0] => 03-03-2018
[1] => 09-03-2018
)
[1] => Array
(
[0] => 10-03-2018
[1] => 16-03-2018
)
[2] => Array
(
[0] => 17-03-2018
[1] => 23-03-2018
)
[3] => Array
(
[0] => 24-03-2018
[1] => 30-03-2018
)
[4] => Array
(
[0] => 31-03-2018
[1] => 06-04-2018
)
)