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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.