morocco-iceberg Posted April 15, 2010 Share Posted April 15, 2010 Just wondering if there's a better/neater way to do this? <?php $a=array("February"); $b=array("April","June","September","November"); $c=array("January","March","May","July","August","October","December"); echo $c[0]; to(); echo "<br/>"; echo $a[0]; te(); echo "<br/>"; echo $c[1]; to(); echo "<br/>"; echo $b[0]; t(); echo "<br/>"; echo $c[2]; to(); echo "<br/>"; echo $b[1]; t(); echo "<br/>"; echo $c[3]; to(); echo "<br/>"; echo $c[4]; to(); echo "<br/>"; echo $b[2]; t(); echo "<br/>"; echo $c[5]; to(); echo "<br/>"; echo $b[3]; t(); echo "<br/>"; echo $c[6]; to(); echo "<br/>"; function te(){ $counter=0; while($counter<28){ $counter=$counter+1; echo " $counter "; } } function t(){ $counter=0; while($counter<30){ $counter=$counter+1; echo " $counter "; } } function to(){ $counter=0; while($counter<31){ $counter=$counter+1; echo " $counter "; } } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Ouch... that was ugly lol. No offense. for ($m = 1; $m <= 12; $m++) { $time = mktime(0, 0, 0, $m, 1, date('Y')); $days = date('t', $time); $month = date('F', $time); echo sprintf("%s - %d<br />", $month, $days); } Try that. Not tested though. Edit - you may need to add something to it to duplicate the effect. Just to get you started. Quote Link to comment Share on other sites More sharing options...
morocco-iceberg Posted April 15, 2010 Author Share Posted April 15, 2010 I actually have to do it using arrays, its a homework assignment, lol, no way I would have used arrays for this purpose unless I was made to. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 I actually have to do it using arrays, its a homework assignment, lol, no way I would have used arrays for this purpose unless I was made to. And you tell me that now? Any other rules we should know about? Do we have to keep the 3 arrays? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 15, 2010 Share Posted April 15, 2010 Put all the months in one array. Get they year from date() then loop through the months array using cal_days_in_month. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
morocco-iceberg Posted April 17, 2010 Author Share Posted April 17, 2010 I guess I should have said so. I'm supposed to have the three seperate arrays according to the amount of days in each month. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.