I need to do a form select from A-Z, how can I do this without being manually? In this case, I would do it manually as follows:
<select>
<option>A</option>
<option>B</option>
<option>Z</option>
</select>
I need to do a form select from A-Z, how can I do this without being manually? In this case, I would do it manually as follows:
<select>
<option>A</option>
<option>B</option>
<option>Z</option>
</select>
Here's hope you'll help:
foreach (range('A', 'Z') as $char) {
echo $char . "\n";
}
Just to complement the response of life.cpp
A good alternative is to use foreach. But how do a repeat if the foreach works with an existing array?
PHP gives us the range()
function that creates an array according to the parameters defined by us.
range ( "inicio" , "fim" [, N ] )
, where N, optional, is a number that defines the number of steps. If omitted is assumed to be 1, that is, all elements will be listed.
Example 1 -: $y = range("a", "z");
look at ideone
Example 2 -: $y = range("a", "z" , 2);
look at ideone
Another way is this example in ideone