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! Link to comment https://forums.phpfreaks.com/topic/218543-help-with-foreach-please/ 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 Link to comment https://forums.phpfreaks.com/topic/218543-help-with-foreach-please/#findComment-1133710 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. Link to comment https://forums.phpfreaks.com/topic/218543-help-with-foreach-please/#findComment-1133711 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/218543-help-with-foreach-please/#findComment-1133714 Share on other sites More sharing options...
dadamssg Posted November 13, 2010 Author Share Posted November 13, 2010 PERFECT. Thanks! Link to comment https://forums.phpfreaks.com/topic/218543-help-with-foreach-please/#findComment-1133716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.