Jump to content

help with foreach please


dadamssg

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.