Question about manipulation of arrays

Discussion in 'PHP' started by Samayel, Feb 4, 2006.

  1. #1
    Hi, I've got this calendar script that I was too lazy to make. It works using arrays of days to highlight(link) to webpages when you click on a day. Here is an example array that will link the second, third and eighth day of the month and link them to different web pages as seen in the array :

    $days = array(
    2=>array('/weblog/archive/2004/Jan/02','linked-day'),
    3=>array('/weblog/archive/2004/Jan/03','linked-day'),
    8=>array('/weblog/archive/2004/Jan/08','linked-day'),
    );

    Now, my problem is that I must make myself a similar array from mySQL dates that I have stored in a table in order to link the right days which contains data to be linked. I tried different approaches but all were unsuccessful.

    At first, I thought something like this might work :

    $year = 2006;
    $month = 1;
    for (i >= 1; i <= $MaxDaysThisMonth; i++) {
    $days[] = $i => array("info.php?date=" . $year . "-" . $month . "-" . $i, 'linked-day') . "," ;
    }

    But apparently I'm still way off :/

    if anyone could help me out that'd be really nice since I'm just starting out :) Thanks in advance.

    -Samayel
     
    Samayel, Feb 4, 2006 IP
  2. averagejoe

    averagejoe Peon

    Messages:
    22
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this?

    
    function zeroPad($a) {
        if (is_int($a) && $a < 10) {
            $a = "0".$a;
        }
        return $a;
    }
    $year = 2006;
    $month = 1;
    $MaxDaysThisMonth = 31;
    for ($i = 1; $i <= $MaxDaysThisMonth; ++$i) {
        $days[$i] = array("info.php?date=" . $year . "-" . zeroPad($month) . "-" . zeroPad($i), 'linked-day');
    }
    
    Code (markup):
     
    averagejoe, Feb 9, 2006 IP