php

How to Populate Dropdown List using Array in PHP

In this tutorial, we are going to see how to populate dropdown list using array in PHP. You can simply use the foreach loop to create a <select> list or any drop-down menu that forms the values of an array.
 

How to Populate Dropdown List using Array in PHP

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Populate Dropdown List using Array</title>
	</head>
	<body>
		<select>
			<option selected="selected">Select a value</option>
			<?php
			$languages = array("PHP", "Java", "Ada", "HTML", "CSS");
			
			// Iterating through the languages array
			foreach($languages as $value){
			?>
			<option value="<?php echo strtolower($value); ?>"><?php echo $value; ?></option>
			<?php
			}
			?>
		</select>
	</body>
</html>
Result
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *