Home  >  Article  >  Backend Development  >  php uses array to populate drop-down list box

php uses array to populate drop-down list box

墨辰丷
墨辰丷Original
2018-06-11 17:51:532826browse

This article mainly introduces the method of using PHP to fill the drop-down list box with an array. It involves the skills of PHP operating arrays. It has certain reference value. Friends in need can refer to it.

The examples in this article describe the use of PHP Method for populating a drop-down list box with an array. The specific implementation method is as follows:

<?php
$data = array(
  (object)array("titulo"=>"Ford", "valor"=>"opcion1"),
  (object)array("titulo"=>"Peugeot", "valor"=>"opcion2"),
  (object)array("titulo"=>"Chevrolet", "valor"=>"opcion3"),
  (object)array("titulo"=>"Volskwagen", "valor"=>"opcion4"),
);
?>
<html>
<header>
<script>
function onCambioDeOpcion(combobox) {
  alert("Seleccionaste: " + combobox[combobox.selectedIndex].text +
   " \nSu valor es: " + combobox.value);
}
</script>
</header>
<body>
<select class="select_autor" name="autor" 
onchange="onCambioDeOpcion(this)" >
<option selected="selected">Seleccione fabricante</option>
<?php
for($i=0; $i<count($data); $i++)
{
?>
  <option value="<?php echo $data[$i]->valor ?>">
  <?php echo $data[$i]->titulo ?></option>
<?php
}
?>
</select>
</body>
</html>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

php method of capturing Thunder VIP accounts based on the collection class Snoopy

php The method of combining the template with the js upload plug-in to achieve refresh-free upload

How to use php to continuously call functions using chain calls

The above is the detailed content of php uses array to populate drop-down list box. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn