John Conde's answer is correct, but here is a more efficient and matte solution:
$start = new DateTime('2013-01-06');
$end = new DateTime('2013-01-20');
$days = $start->diff($end, true)->days;
$sundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7);
echo $sundays;
Let me break it for you.
$start = new DateTime('2013-01-06');
$end = new DateTime('2013-01-20');
First, create DateTime objects , which are powerful PHP built-in objects designed specifically for this kind of problem.
$days = $start->diff($end, true)->days;
DateTime:: diff, $start $end ( true , ) .
$sundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7);
- , . -, , , $days / 7 , int intval.
, ; , - 4 ; - . , , , . :
7 , . , , 1, 0, , int.
! , , , , , . , !