Page 1 of 1

Trouble using function range to generate an array

Posted: Sun Jan 14, 2007 4:50 pm
by impulse()
I'm trying to create a date drop-down box with a drop down menu for each day, month and year. I'm using the

Code: Select all

range
function to put 31 days in a month, 12 months in a year and a 10 year span. Trouble being is that it puts "Array" in the drop down box, but if I don't use the range function and put the values in the array manually it generates the drop down menu fine.

Code:

Code: Select all

$day = array(range(1,31));

echo "<select name = 'day'>";

foreach ($day as $a) {
  echo "<option value = '$a'> $a </option>";
}

echo "</select>";

Posted: Sun Jan 14, 2007 4:54 pm
by decipher
don't declare it as an array, it will default to a multidimensional array if you do that, as range() returns as an array.

Code: Select all

$day = range(1,31);