0

Is it possible to assign a php variable durin html code, I've created my first php Programm and i wanted to make a dropdown bar like this:

<select>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
  <option>7</option>
  <option>8</option>
  <option>9</option>
  <option>10</option>
</select>

I wanted to know if it is possible to assign the variable "x", to the value, the user of the website has chosen.

2
  • are you looking for <option>$x</option> stackoverflow.com/questions/20177788/… Commented Dec 11, 2019 at 20:46
  • Your select needs a name <select name="something"> Commented Dec 11, 2019 at 21:12

1 Answer 1

-1
<select>

    <?php

    $x = "value";

    foreach (range(1, 10) as $i) {

        echo "<option value=\"" . $x . "\">" . $i . "</option>";
    }
    ?>

</select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.