Mount A-Z listing in PHP

0

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>
    
asked by anonymous 04.09.2017 / 18:36

2 answers

6

Here's hope you'll help:

foreach (range('A', 'Z') as $char) {
   echo $char . "\n";
}
    
04.09.2017 / 18:45
1

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

To test the range online function

    
04.09.2017 / 21:22