tags:

views:

22

answers:

2

Hi,

Basic question here. I am using php(smarty) range to populate an array for days in the month.

$smarty->assign('date', range(1,31 ));

The form sends OK, but because counts start at 0, when I pick 20 from dropdown 19 gets sent in the form.

How do I set it so it starts at 1?

+1  A: 

The range() function does not allow you to specify the keys for the array. The simplest option would be to create your own array:

$range = array();
for ($i = 1; $i <= 31; $i++) {
    $range[$i] = $i;
}
$smarty->assign('date', $range);
lonesomeday
+1  A: 
$days = array_combine(range(1,31),range(1,31));

Or, possibly more efficient, although it's a micro-optimalisation:

$range = range(1,31);
$days = array_combine($range,$range);
Wrikken