Not sure if i should be using php or JavaScript however i have a form that uses the following checkboxes

td>How do you get to work?</td>
                    <td><input type="checkbox" name="vehicle" value="Train" />Train
                    <input type="checkbox" name="transport[]" value="Bus" />Bus
                    <input type="checkbox" name="transport[]" value="Car" />Car
                    <input type="checkbox" name="transport[]" value="Bicycle" />Bicycle
                    <input type="checkbox" name="transport[]" value="Walk" />Walk</td>
                    </tr>

In my php file i have to print to the screen the transport options which have been selected however before i do this i have to use a for loop to iterate over the elements in the array and have to use the function count to determine how many elements are in the array. I have no idea what why this should be written and also if the checkboxes names transport [] should include numbers for their position in the array like transport [0] etc. Any help would be great.

<?
    if(form is submitted)
    {
        $transportAll = $_POST['transport'];
        foreach($transportAll as $transport)
        {
            echo '<br />You have selected:'.$transport;
        }
        echo '<br />Total:'.count($transportAll);
    }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.