How to select multiple values using dropdown in php?

6

<?php
if(isset($_POST[‘btn’])){
if(isset($_REQUEST[‘menu’])){
$menu=$_REQUEST[‘menu’];
foreach($menu as $key=>$value){
if(is_array($value)){
foreach($value as $item){
echo $item.“<br>”;
}
}

else{
echo $value.“<br>”;
}
}
}
else{
echo “please select any option”;
}
}
?>
<html>
     <head>
     <title>PHP Example</title><br>
<body>
<form name=“frm” action=“multiple_dropdown.php” method=“post”>
<b>Select your favorite ice_cream flavour(s)</b><br>
<select name=“menu[]” multiple>
<option value=“ice cream”>ice cream</option>
<option value=“coffee”>coffee</option>
<option value=“tea”>tea</option>
<option value=“beverage”>beverage</option>
<option value=“cold coffee”>cold coffee</option>
</select><br>
<input type=“submit” name=“btn” value=“submit” />
</form>
</body>
     </html>

Please follow and like us:
0

Add a Comment

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