What I’m interested in doing is creating a range of numeral values for an html drop down menu, ranging from 18 to 75. My client is asking that between the numbers 29 and 30, I interrupt the range with the value ‘Choose’, which would be the default option.
I don’t see this as necessary, but I thought I’d play around and see if it’s even possible. The range is already created, so now I’ve got to find a way to reliably insert ‘Choose’ into the middle of it. I’ve tried a few things based on google searches and comments in the function’s manual, so now I’m turning to stack. Thanks for any advice!
edit: Here is the code…
<?php
$age = range(18, 75);
echo ( '<select class="dropdown nextPanel" name="age">' );
foreach ($age as $option){
echo ( "<option value='".$option."'>".$option."</option>" );
}
echo ( '</select>' );
?>
Another edit: Crap, I suppose I’m trying to interrupt a foreach.
So you’ve got the range (using
range(18, 75)?) and want to insertChoosebetween 29 and 30?That will insert ‘Choose’ right after the value
29in$range.If you want to do it only when it’s being printed, you can look at ehudokai’s answer for a start.
EDIT: If all you want to do is insert the ‘Choose’ option after option number 29, and set it as the default option in a select:
This way it will still print out the regular options, but when it encounters option
30, it will first print out the defaultchooseoption, and mark it as selected.