Code: Select all
<html>
<head><title>Grouping form array</title></head>
<body>
<?php
if (!isset($_POST['submit'])){
?>
<form action="array.php" method="post">
<select name="options[]" multiple>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="submit" name="submit" value="send" />
</form>
<?php
} else {
if (is_array($_POST['options']))
foreach ($_POST['options'] as $a){
echo $a;
//$c = 10 $a 10;
//echo $c;
}
else {
echo "Please select at least one";
}
}
?>
</body>
</html>
//echo $c; it will cause and error but If remove it it will only display the user's selection.
Another thing when the user don't choose anyone from the option it will trigger an error "
Notice: Undefined index: options in C:\wamp\www\edilyn4care\array.php on line 19
Please select at least one ". Thanks for your help.