Jump to content

[SOLVED] Loop through days in a month?


Solarpitch

Recommended Posts

Hey Guys,

 

Is there a function I can use that will loop through a month returning each day. I would need something like

 

<?php
//loop through $month array here?
//then do...

foreach($month as $day)
{
$links = array(
               $day  => 'http://www.mysite.com/calender/2009/03/$month',
               );
}
?>

 

EDIT: SO basically if I could pass in the month as a number... 1 for Jan, 2 for feb... etc thats what I would need. Then it would create my array, as above like...

 

1 => 'http://www.mysite.com/calender/2009/01/1',
2 => 'http://www.mysite.com/calender/2009/02/1',
3  => 'http://www.mysite.com/calender/2009/03/1',
....
31  => 'http://www.mysite.com/calender/2009/31/1',

Link to comment
Share on other sites

Cheers. Just one more question before I potter along. My array knowledge is not fully flexed in php at the moment so there may be a reason as to why the links array keeps overwriting each value and it just ends up holding the last value in the loop... which in this case is the 31st

31 => 'http://www.mysite.ie/enterprise/index.php/enterprise/dashboard/2009/01/31');

 

To me this makes logical sense and should produce...

1 => 'http://www.mysite.com/calender/2009/01/1',
2 => 'http://www.mysite.com/calender/2009/02/1',
3  => 'http://www.mysite.com/calender/2009/03/1',
....
31  => 'http://www.mysite.com/calender/2009/31/1',

 

<?php
$date = mktime(0,0,0,3,1,$year); //The get's the first of March 2009
$links = array();
for($n=1;$n <= date('t',$date);$n++){
$links = array($n => 'http://www.mysite.ie/enterprise/index.php/enterprise/dashboard/'.$year.'/'.$n.'/1');
}  
?>

Link to comment
Share on other sites

nope...you keep assigning a new array to $links each time. this is what you want:

<?php
$date = mktime(0,0,0,3,1,$year); //The get's the first of March 2009
$links = array();
for($n=1;$n <= date('t',$date);$n++){
$links[$n] = 'http://www.mysite.ie/enterprise/index.php/enterprise/dashboard/'.$year.'/'.$n.'/1';
}  
?>

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.