# How to understand this code and understand the algorithm?

``````<?php
function getDay(\$year,\$mon,\$day)
{
\$days = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
\$day = (int)\$day; //if day of two-character and <10
\$mon = (int)\$mon; //if the two-character month and <10
\$a = (int)((14 - \$mon) / 12); // 1
\$y = \$year - \$a; // 2015
\$m = \$mon + 12 * \$a - 2; // 4
\$d = (7000 + (int)(\$day+\$y+ (int)(\$y/4) - (int)(\$y/100) + (int)(\$y/400) + (31*\$m)/12))%7;
return \$days[\$d];
}
echo getDay(2016,06,05);
?>``````

Please help me with this code, tell us the algorithm and what is responsible for what!!! I really want to understand, but nothing happens. I would be very grateful if shall describe the operation of this code, or throw off a resource where this is described in detail! Thanks in advance:)
July 8th 19 at 11:38
July 8th 19 at 11:40
Solution
Here is the counterpart!
Then I think will be easier to understand:
``````function getDay(\$d, \$m, \$y) {
\$arrDays = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

\$n = date('w', mktime(0, 0, 0, \$m, \$d, \$y));
return \$arrDays[\$n];
}

echo getDay(27, 06, 2016);``````
July 8th 19 at 11:42

Find more questions by tags PHP