title: set checkbox checked state based on array values
body: <p>Let's say I have a bunch of checkbox inputs initially on a page like this:</p>
  
  <pre><code>&lt;input type="checkbox" name="vehicle" value="Car" /&gt; Car&lt;br /&gt;
  &lt;input type="checkbox" name="vehicle" value="Bike" /&gt; Bike&lt;br /&gt;
  &lt;input type="checkbox" name="vehicle" value="Motorcycle" /&gt; Motorcycle&lt;br /&gt;
  &lt;input type="checkbox" name="vehicle" value="Bus" /&gt; Bus&lt;br /&gt;
  &lt;input type="checkbox" name="vehicle" value="Car" /&gt; Train&lt;br /&gt;
  </code></pre>
  
  <p>Now let's say that I have an array like this:</p>
  
  <pre><code>$my_array = array(
      'first' =&gt; 'Bike', 
      'second' =&gt; 'Car', 
      'third' =&gt; 'Train'
  );
  </code></pre>
  
  <p>As you can see, my array contains values which correspond to the value of my checkboxes.</p>
  
  <p>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?</p>
  
  <p>Any idea please? I have tried almost everything with no success</p>