PHP array array Select using

I have a php array ....

<?php $state = array("Kentucky", "Ohio", "West Virginia", "Indiana", "Texas");

How do I get this request to report this selection list.

<select size="1" name="state" id="state">
 <option>Select One</option>
</select>
+3
source share
3 answers
<select size="1" name="state" id="state">
<?php
foreach($state as $state_name)
{
   echo '<option value="' . $state_name . '">' . $state_name . '</option>';
}
?>
</select>
+1
source
<?php 
$state = array("Kentucky", "Ohio", "West Virginia", "Indiana", "Texas");
?>

<select size="1" name="state" id="state">
<option>Select One</option>
<?php 
   foreach($state AS $val){
       echo "<option>$val</option>";
   }
 ?>
</select>

Gotta do the trick

+2
source

You can explode (expand the array)

<select size="1" name="state" id="state">
<option>Select One</option>
<option>
<?php
  $state = array("Kentucky", "Ohio", "West Virginia", "Indiana", "Texas");
  echo implode('</option><option>', state);
?>
</option>
</select>
+1
source

Source: https://habr.com/ru/post/1791369/


All Articles