Jump to content

[SOLVED] drop down list from an array


jim.davidson

Recommended Posts

I'm trying to teach myself php.

 

Today's mission learn to build and display arrays

 

I want the array to contain a valid year of birth for anyone between the ages of 16 and 80.  I'm pretty sure this code is correct.(though it might be a bit sloppy to all you pros)

 

$dob_dates = array();

$today = date('Y');

$startyear = $today - 80;

$endyear = $today - 16;

$n = 0;

$i = $startyear;

while ($i <= $endyear) {

  $dob_dates[$n] = ($startyear+$n);

  $i++;

  $n++;

}

 

Now that I've built an array containing valid dob years I want to have a drop down list showing the array.  Can someone show me the light on how to do that?

 

Any and all help will be appreciated

Link to comment
https://forums.phpfreaks.com/topic/69785-solved-drop-down-list-from-an-array/
Share on other sites

No problem ;D

 

Does it work how you want it to ???

 

1. Anyways, it is very simple, its a basic for loop which

  i) Sets $i to 0,

  ii) then checks that $i is less than or equal to $n, if not then the loop ends

  iii) lastly after each loop is will increment $i by 1 until $i is greater than $n

 

2. It then gets the $i value of the array and then takes it from the variable and puts it within the <option> tag

 

Hope that helps ;D

 

~ Chocopi

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.