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>