initial value in a month array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jspot
    New Member
    • Sep 2006
    • 3

    initial value in a month array

    I have set up an array that includes the months of the year.

    <?php
    // define array
    $month = array('January' , 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    // loop over it
    // print array elements
    foreach ($month as $a) {
    echo '<br>'.$a;
    }
    ?>

    Is there a way to have this start with the current date?

    I've seen date("m") used to pull the current date and have it set as the option value in a select box, but not in the array itself.

    Any help would be greatly appreciated.
  • pasupathi
    New Member
    • Aug 2006
    • 5

    #2
    use the function now() and try

    Comment

    • jspot
      New Member
      • Sep 2006
      • 3

      #3
      This is the code I finally came up with.
      Hope this helps someone else!

      <?php
      $month = array
      ('now -1 months',
      'now -2 months',
      'now -3 months',
      'now -4 months',
      'now -5 months',
      'now -6 months',
      'now -7 months',
      'now -8 months',
      'now -9 months',
      'now -10 months',
      'now -11 months',
      'now -12 months');

      foreach ($month as $a) {
      $date=strtotime ("$a");
      $date=date("F", $date);
      echo '<br>'.$date;
      }
      ?>

      Comment

      • jspot
        New Member
        • Sep 2006
        • 3

        #4
        Below is the code that will pull current month first. The previous example was a month behind.

        <?php
        $month = array
        ('now',
        'now -1 months',
        'now -2 months',
        'now -3 months',
        'now -4 months',
        'now -5 months',
        'now -6 months',
        'now -7 months',
        'now -8 months',
        'now -9 months',
        'now -10 months',
        'now -11 months');

        foreach ($month as $a) {
        $date=strtotime ("$a");
        $date=date("F", $date);
        echo '<br>'.$date;
        }
        ?>

        Comment

        Working...