PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
this code is from a php file,which use the smarty template.can't understand the get_total_day($date) function,why the $i value starts from 28,and ends on 32.
foreach (array_keys($week_days) as $day)
$days[] = $day;
for ($i=0; $i<$starting_day; $i++)
$days[] = " ";
for ($i=1; $i< ($total_day_of_month+1); $i++)
$days[] = $i;
what about these mean? any tips would be appreciated.
I'm quite new to php.
So i might be wrong.
But I belive that the function checks if the month has 30 or 31 days
it starts on 28 beacuse feb might have 28 days
It 's unnecessary to check if days 1 to 27 exsits, beacuse they always will, 28-31 might not.
foreach (array_keys($week_days) as $day)
$days[] = $day;
for ($i=0; $i<$starting_day; $i++)
$days[] = " ";
for ($i=1; $i< ($total_day_of_month+1); $i++)
$days[] = $i;
now,$days[] is an arry,which value is sat,aun,mon..the rest i also don't catch up with it. i don't find the place that declare this $starting_day variable.
$starting_day = $week_days[Date("D",strtotime($date))] - 1; // Get week day of date and then get nr from array
foreach (array_keys($week_days) as $day) // get keys in array (Sat,Sun,Mon)
$days[] = $day; // Add day in to days array
for ($i=0; $i<$starting_day; $i++) // Count from 0 to starting day (Fri = 7)
$days[] = " "; // Add space to array
for ($i=1; $i< ($total_day_of_month+1); $i++) // count from 1 to nr of days in mount + 1
LuaMadman wrote:I'm quite new to php.
So i might be wrong.
But I belive that the function checks if the month has 30 or 31 days
it starts on 28 beacuse feb might have 28 days
It 's unnecessary to check if days 1 to 27 exsits, beacuse they always will, 28-31 might not.
oh,but if $i=28,then it will return 27, that is the for loop will return 27,28,29,30,32,how the function only checks if the month has 30 or 31 days?
it has !checkdate() with tells it if dates does not exist then do code bellow. in this code $i - 1
So if $i=28 it will check to see if 28 exist, confirm that it does, move on to 29, confirm that' it don't exist, and then do $i - 1 to return that 28 was the last found.
or if $i=31 it will check that 28,29,30 exist, they all do. if 31 does not exists, it does $i - 1 and return 30. if 31 exists, it will check if 32 does, it dosen't, so it do $i-1 and return 31
LuaMadman wrote:it has !checkdate() with tells it if dates does not exist then do code bellow. in this code $i - 1
So if $i=28 it will check to see if 28 exist, confirm that it does, move on to 29, confirm that' it don't exist, and then do $i - 1 to return that 28 was the last found.
or if $i=31 it will check that 28,29,30 exist, they all do. if 31 does not exists, it does $i - 1 and return 30. if 31 exists, it will check if 32 does, it dosen't, so it do $i-1 and return 31
i know,i know...many many thanks to you! in this example,the month is Jan,so the $i=32 will not exist, it will return 31.am i right.