Is there a way of creating an age select list like this:
<?php
$Array = array('99','98','97','96');
?>
<select name="age">
<option value="" selected>Choose</option>
<?php foreach($Array as $value){ echo('<option value="' . $value . '">' . $value . '</option>');}?>
</select>
but without a really long array as I want age range to be from say 18 upto 100 and that would take forever to writeout?
Using a basic for
loop:
<?php
for($value = 18; $value <= 100; $value++){
echo('<option value="' . $value . '">' . $value . '</option>');
}
?>
PHP has a range function that you can use in order to generate an array made up of a range of numbers.
foreach (range(0, 12) as $value ) {
echo('<option value="' . $value . '">' . $value . '</option>');
}