php uses array to populate drop-down list box

墨辰丷
Release: 2023-03-31 16:32:01
Original
2814 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template