I know this topic is old, but this is a shorter way to do this using the elvis operator and the +7 day expression for strtotime ():
$week=date("W",strtotime(date("w")==1?"+7 day":"+0 day"));
if $ date ("w") returns true, then today is the day between Tuesday and Sunday (1-6), so we can return today for a week ("today").
if it returns false, it means Monday (0), so we must return the next day ("+1 week").
Thus, we do not need to care about the last or first day of the year or check whether the current year has 52 or 53 weeks.
Edited: the previous answer (and others in this section) does not work this year because januray 1st is Monday, so it should be 1 week ago (-1 week), except Sunday (6th day).
date("W",strtotime(date("w")?'-7 day':'+0 day'));
I think a condition asking if januray 1st monday can work, but I have not tested it yet, I will come back with an answer later
For a custom day, you can use this:
$date = strtotime('2018-04-30'); // (it is monday) if(date("w",strtotime(date('Y',$date).'-01-01'))==1){ // if first day of year is monday $week = strtotime(date('w',$date)?"-7 day":"+0 day",$date); // and today is sunday, sub a week $week = date("W",$week); }else{ // if is not monday $week = strtotime(date('w',$date)==1?"+7 day":"+0 day",$date); // and today is monday, add a week $week = date("W",$week); }