dadamssg Posted November 13, 2010 Share Posted November 13, 2010 I am trying to develop a calendar. I have code to determine the number of days for each month. I want to cycle through each day and spit out code for each day. Something like the following: <?php $month = "December"; $days = 31; foreach($days){ echo "<div id='day_block'> ".$days." </div>"; } ?> i think i need to use a counter but don't know how, any help would be awesome! Quote Link to comment Share on other sites More sharing options...
Vitamin Posted November 13, 2010 Share Posted November 13, 2010 foreach loops are for arrays and because $days is a int its not going to work. The correct syntax is foreach ($array as $value) { //code } I know that does not really answer your question, but once you put the days into an array it will start to piece it self together Quote Link to comment Share on other sites More sharing options...
dadamssg Posted November 13, 2010 Author Share Posted November 13, 2010 i thought there was a way to run through an array using a count, i remember seeing "i++" that were suppose to add to the count. I know there's a way to to do it, just can't recall how. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted November 13, 2010 Share Posted November 13, 2010 You don't need foreach, you just need a straight for: <?php $month = "December"; $days = 31; for($day = 1; $day <= $days; $day++){ echo "<div id='day_block'> ".$day." </div>"; } ?> Quote Link to comment Share on other sites More sharing options...
dadamssg Posted November 13, 2010 Author Share Posted November 13, 2010 PERFECT. Thanks! 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.