<?php
function weekOfMonthWithWeek($date)
{
$c = 0;
$i = 1;
$weeks['month_year'] = "$y - $m";
{
if ($s == 6)
{
$s = 0;
$weeks['items'][] = array('week' => $i++, 'total_days' => $c+1); $c = 0;
}
else
{
$c++;
$s++;
}
}
if ($s != 0) $weeks['items'][] = array('week' => $i++, 'total_days' => $c);
return $weeks;
}
var_dump ( weekOfMonthWithWeek
('2017-01-20') );
PD9waHAKCglmdW5jdGlvbiB3ZWVrT2ZNb250aFdpdGhXZWVrKCRkYXRlKSAKCXsKCQlsaXN0KCR5LCAkbSwgJGQpID0gZXhwbG9kZSgnLScsICRkYXRlKTsKCQkkd2Vla3MgPSBhcnJheSgpOwoJCSRzID0gZGF0ZSgndycsIHN0cnRvdGltZSgieyR5fS17JG19LTAxIikpOyAvLyAyCgkJJHQgPSBkYXRlKCd0Jywgc3RydG90aW1lKCJ7JHl9LXskbX0tMDEiKSk7IC8vIDIKCQkkYyA9IDA7CgkJJGkgPSAxOwoJCSR3ZWVrc1snbW9udGhfeWVhciddID0gIiR5IC0gJG0iOwoJCWZvcigkaW5pID0gZGF0ZSgnWS1tLWQnLCBzdHJ0b3RpbWUoInskeX0teyRtfS0wMSIpKTsKCQkJJGluaSA8PSBkYXRlKCdZLW0tZCcsIHN0cnRvdGltZSgieyR5fS17JG19LXskdH0iKSk7CgkJCSRpbmkgPSBkYXRlKCdZLW0tZCcsIHN0cnRvdGltZSgkaW5pLiIgKzEgZGF5cyIpKSkKCQl7CgkJCWlmICgkcyA9PSA2KQoJCQl7CgkJCQkkcyA9IDA7CQkJCQoJCQkJJHdlZWtzWydpdGVtcyddW10gPSBhcnJheSgnd2VlaycgPT4gJGkrKywgJ3RvdGFsX2RheXMnID0+ICRjKzEpOwkKCQkJCSRjID0gMDsKCQkJfQoJCQllbHNlCgkJCXsKCQkJCSRjKys7CgkJCQkkcysrOwoJCQl9CgkJCQoJCX0KCQlpZiAoJHMgIT0gMCkgJHdlZWtzWydpdGVtcyddW10gPSBhcnJheSgnd2VlaycgPT4gJGkrKywgJ3RvdGFsX2RheXMnID0+ICRjKTsKCgoJCXJldHVybiAkd2Vla3M7Cgl9CgoKCXZhcl9kdW1wICggd2Vla09mTW9udGhXaXRoV2VlaygnMjAxNy0wMS0yMCcpICk7