Using arrays with checkboxes

We have all used checkboxes, to add features, assign permissions, etc. There is a method you can use do give the same name to each checkbox, with a different value. This can come in handy for a variety of applications, parts, vehicles, inventory, etc.
In this example you are wanting to know what type of vehicle you have. Here are typical check boxes:

<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br>

With the option to choose multiple parts we find there is a problem. You have to have a different name for each vehicle, since you cannot use the same name, or can you? Yes you can, just change the name attribute to vehicle[], so your html will look like this:

<input type="checkbox" id="vehicle[]" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle[]" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle[]" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br>

If you were to select all three your would have an array with the following returned in $_POST:

vehicle[]=Bike&vehicle[]=Car&vehicle[]=Boat

Or if you were to selected only two you would have:

vehicle[]=Car&vehicle[]=Boat