Newbie: Question regarding Arrays
Posted: Wed Jul 23, 2008 10:55 am
I am brand new to PHP (after just learning html and CSS) and am following along in a book on writing php.
The code below should produce a Month, Day and Year drop down box. While the Day and Year are fine, the Months are displayed without a dropdown. I've been going over this for over an hour and can't figure it out. Please help.
<?php
// This script makes three pull-down menus
// For and HTML form: months, days, years.
// Make the Months array:
$months = array (1 => 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December');
// Make the days and years arrays:
$days = range (1, 31);
$years = range (2008, 2018);
// Make the Months pull-down menu:
echo '<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\"> $value</option>\n";
}
echo '</select>';
// Make the Days pull-down menu:
echo '<select name="day">';
foreach ($days as $value) {
echo "<option value=\"$value\"> $value</option>\n";
}
echo '</select>';
// Make the Years pull-down menu:
echo '<select name="year">';
foreach ($years as $value) {
echo "<option value=\"$value\"> $value</option>\n";
}
echo '</select>';
?>
</form>
</body>
</html>
The code below should produce a Month, Day and Year drop down box. While the Day and Year are fine, the Months are displayed without a dropdown. I've been going over this for over an hour and can't figure it out. Please help.
<?php
// This script makes three pull-down menus
// For and HTML form: months, days, years.
// Make the Months array:
$months = array (1 => 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December');
// Make the days and years arrays:
$days = range (1, 31);
$years = range (2008, 2018);
// Make the Months pull-down menu:
echo '<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\"> $value</option>\n";
}
echo '</select>';
// Make the Days pull-down menu:
echo '<select name="day">';
foreach ($days as $value) {
echo "<option value=\"$value\"> $value</option>\n";
}
echo '</select>';
// Make the Years pull-down menu:
echo '<select name="year">';
foreach ($years as $value) {
echo "<option value=\"$value\"> $value</option>\n";
}
echo '</select>';
?>
</form>
</body>
</html>