I have this situation:
<select name="year" >
<?php
$today = date("Y");
for ($i=2005; $i<=$today; $i++){
echo "<option value=\"$i\">$i</option>";
}
?>
</select>
This will give me the years 2005 through 2011, ...
in zend framework a drop down will look like this:
$this->addElement('select', 'department', array(
'label' => 'Year:',
'multiOptions' => array('A' => 'A', 'B' => 'B', 'C' => 'C',),
'value' => @$val->_listing_type_id
));
How can I translate my for loop script to create the years in the Zend Framework script? I know I can use the first script in Zend Framework but I want to keep the syntax consistent.
Any ideas?
You could use
rangeto create an array of numbers from 2005 to 2011:If Zend really does expect an array where the keys/values must be the same, you can use
array_combineto produce the required array:This will produce
array(2005 => 2005, 2006 => 2006, ..., 2011 => 2011).