Home >Backend Development >PHP Tutorial >How to use php array to fill drop-down list box, php array drop-down list box_PHP tutorial
This article describes the method of php using array to fill drop-down list box. Share it with everyone for your reference. 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>
I hope this article will be helpful to everyone’s PHP programming design.