1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6. <title>Date Menus</title>
7. </head>
8. <body>
9. <?php // Script 10.3 - menus3.php
10. /* This script defines and calls a function that takes arguments. */
11.
12. // This function makes three pull-down menus for the months, days, and years.
13. // This function requires two arguments be passed to it.
14. // The second argument has a default value of 10.
15. function make_date_menus($start_year, $num_years = 10) {
16.
17. // Array to store the months:
18. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
19.
20. // Make the month pull-down menu:
21. print '<select name="month">';
22. foreach ($months as $key => $value) {
23. print "\n<option value=\"$key\">$value</option>";
24. }
25. print '</select>';
26.
27. // Make the day pull-down menu:
28. print '<select name="day">';
29. for ($day = 1; $day <= 31; $day++) {
30. print "\n<option value=\"$day\">$day</option>";
31. }
32. print '</select>';
33.
34. // Make the year pull-down menu:
35. print '<select name="year">';
36. for ($y = $start_year; $y <= ($start_year + $num_years); $y++) {
37. print "\n<option value=\"$y\">$y</option>";
38. }
39. print '</select>';
40.
41. } // End of make_date_menus() function.
42.
43. // Make the form:
44. print '<form action="" method="post">';
45. make_date_menus(2009, 15);
46. print '</form>';
47.
48. ?>
49. </body>
50. </html>