Mount A-Z listing in PHP

Asked

Viewed 110 times

0

Need to make a form select of 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>

2 answers

6


Here’s hoping you can help him:

foreach (range('A', 'Z') as $char) {
   echo $char . "\n";
}

1

Just to complement the answer from life.cpp

A good alternative is to use foreach. But how to do a repeat if foreach works with an existing array?

PHP provides us with the function range() that creates an array according to the parameters defined by nodes.

range ( "inicio" , "fim" [, N ] ), where N, optional, is a number that defines the number of steps. If omitted is set to 1, that is, all elements will be listed.

Example 1 - : $y = range("a", "z"); see in ideone

Example 2 - : $y = range("a", "z" , 2); see in ideone

Another way is according this example in ideone

To test the range function online

Browser other questions tagged

You are not signed in. Login or sign up in order to post.