Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

How to do a foreach loop for 1-10

Hi,

I have an drop down where I want users to choose between 0 and 10. Right now I am doing it

<select name="immersiveScore" id="immersiveScore" class="form-control" required>
                <option value="" hidden>Choose Immersive Score</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
            </select>

but this seems like the wrong way to do it if I have access to PHP. Also it doesnt allow me to grab the data from the table and fill in the selected option if the user goes back to this select field. Im guessing I would want to do a foreach but I dont have that data anywhere unless someone creates each of the 1-10 variables and puts them into my database.

Is there a way to setup a foreach just for the integers 1-10 so I can then do a selected if the user has already saved this data and comes back?

0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

Didn't read full post, according to your title and code

foreach (range(0, 10) as $item) {
    echo $item;
}
2 likes

Please or to participate in this conversation.