i try to write a code that shows the total days of the all months in 2009. This is for practice but i could't fint how to write the total days of all months. it must be like this
the days of January is: 31
the days of February is:28
the days of March is:31
the days of April is:30
the days of May is:31
the days of June is:30
the days of July is:31
the days of August is:31
the days of September is:30
the days of October is:31
the days of November is:30
the days of December is:31
help for my practice
Moderator: General Moderators
Re: help for my practice
First create an array:
and so forth, including all the months.
Then loop through the array:
Code: Select all
$days = array('January'=>31, 'February'=>28);
Then loop through the array:
Code: Select all
foreach($days as $k=>$v) {
echo 'The days of ' . $k . ' are ' . $v . '.<br />';
}
Re: help for my practice
that works but what can i do if i want to take the year from the user. what i mean is that what will happen if i don't know how many days is February in 2020
Re: help for my practice
Code: Select all
<?
$year = 2009;
for($i=0; $i<12; $i++){
echo date("t", mktime(0, 0, 0, $i, 1, $year));
echo '<br />';
}
?>