Trouble using function range to generate an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Trouble using function range to generate an array

Post 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>";
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post 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);
Post Reply