Using Arrays with Form Data in PHP : _GET « Form « PHP






Using Arrays with Form Data in PHP

 
<SELECT NAME="myselect[]" MULTIPLE SIZE=3>
<OPTION VALUE="value1">A</OPTION>
<OPTION VALUE="value2">B</OPTION>
<OPTION VALUE="value3">C</OPTION>
<OPTION VALUE="value4">D</OPTION>
</SELECT>


//The PHP code to access which value(s) were selected:

<?php
     foreach($_GET['myselect'] as $val) {
          echo "You selected: $val<BR>";
     }
     echo "You selected ".count($_GET['myselect'])." Values.";
?>
  
  








Related examples in the same category

1.Properly Checking for Submission Using Image Widgets
2.Time-Sensitive Form Example
3.Reading Input from the Form