Home > Article > Backend Development > php uses array to populate drop-down list box
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!