2008/5/10 Ron Piggott <[EMAIL PROTECTED]>:
> I am wanting to change
>
>         echo "<option value=\"" . $months[$month] . "\"";
>
> to output the month number, between 01 and 12 --- DATE value m, the
> month with leading 0's.  How do I do this?  $months is an array, as I
> have shown below.  Ron
>
> <?php
> $months = array('1' => 'January', '2' => 'February', '3' => 'March', '4'
> => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August',
> '9' => 'September', '10' => 'October', '11' => 'November', '12' =>
> 'December');
>
> $current_month = DATE("n");
>
> echo "<SELECT NAME=\"order_received_month\">\r\n";
>
> foreach (range(1, 12) as $month)
>     {
>         echo "<option value=\"" . $months[$month] . "\"";
>
> if ( $month == $current_month ) { echo " SELECTED";}
>
> echo">" . $months[$month] . "</option>\r\n";
>     }
> ?>
> </select>

Try this (from memory, untested).

for ($i = 1; $i >= 12; $i++)
{
    $month = date( 'm', strtotime( "1970-$i-01" ));
    echo "<option value=\"$i\">$month</option>";
}

Or this:

printf( "%02d", 5 );

However, please consider replacing numeric identifiers for months with
textual ones ('M' rather than 'm'). [01] [Apr] [2008] doesn't cause
the confusion that [01] [04] [2008] does.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to