Let's say you have html form where in you can accept multiple values for a same field and the GUI has to be presented as a series of checkboxes the user can check/uncheck.

This is done  by using the array index operator ‘[]’ to the name attribute of the checkbox element as show below:

<form method="POST" action="...">
Maths <input type="checkbox" name="subject[]" value="math" />
Science <input type="checkbox" name="subject[]" value="science" />
English <input type="checkbox" name="subject[]" value="english" />
Social <input type="checkbox" name="subject[]" value="social" />


Lets say we are using PHP for the serverside, then we can use the

$_POST['subject'] variable to get all the values that were selected by the user as an array. For example of all these checkboxes were selected then the output will be.


// output
    [0] => math
    [1] => science
    [2] => english
    [3] => social )