Let's say I have a bunch of checkbox inputs initially on a page like this:
<input type="checkbox" name="vehicle" value="Car" /> Car<br />
<input type="checkbox" name="vehicle" value="Bike" /> Bike<br />
<input type="checkbox" name="vehicle" value="Motorcycle" /> Motorcycle<br />
<input type="checkbox" name="vehicle" value="Bus" /> Bus<br />
<input type="checkbox" name="vehicle" value="Car" /> Train<br />
Now let's say that I have an array like this:
$my_array = array(
'first' => 'Bike',
'second' => 'Car',
'third' => 'Train'
);
As you can see, my array contains values which correspond to the value of my checkboxes.
Now, how do I set the state of each checkbox input based on the value of my array and make the checkbox stay checked even on page refresh using php? In other words, I want to display all the checkboxes on my page but only those whose values match the value in my array should be checked on the page. Is this possible with just straight PHP or do I need javascript for this?
Any idea please? I have tried almost everything with no success