title: checkbox checked with php on page load
body: <p>I am new in programing and stuck at a point. I am using an API which returns multiple values in an array. I get these values in a form which contain check boxes, I just want those check boxes to be checked which have been returned by API. Means it like a ticketing system. For example i have array of seatdata and i want to checked those checkboxes which has id in php array. </p>
  
  <pre><code>&lt;?php
  $seatdata = array("A1", "A6", "A10","A11");
  ?&gt;
  
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|12' id="A11"   /&gt;&lt;label for="A11"&gt;A11&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|11' id="A10"/&gt; &lt;label for="A10"&gt;A10&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|10' id="A9" /&gt;&lt;label for="A9"&gt;A9&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|9' id="A8" /&gt;&lt;label for="A8"&gt;A8&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|6' id="A7" /&gt;&lt;label for="A7"&gt;A7&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|5' id="A6" /&gt;&lt;label for="A6"&gt;A6&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|4' id="A5" /&gt;&lt;label for="A5"&gt;A5&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|3' id="A4" ?&gt; /&gt;&lt;label for="A4"&gt;A4&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|2' id="A3" /&gt;&lt;label for="A3"&gt;A3&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|1' id="A2" /&gt;&lt;label for="A2"&gt;A2&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type='checkbox' name='seatdata[]' value='0|0' id="A1"/&gt;&lt;label for="A1"&gt;A1&lt;/label&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>I have also tried below code but its not working</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;script type="javascript"&gt;
  
  var data = ["A1", "A6", "A10","A11"];
  
  $.each(data,function(i,v){
  
  $('#'+v).prop('checked',true)
  
  });
  
  &lt;/script&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|12' id="A11" /&gt;
    &lt;label for="A11"&gt;A11&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|11' id="A10" /&gt;
    &lt;label for="A10"&gt;A10&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|10' id="A9" /&gt;
    &lt;label for="A9"&gt;A9&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|9' id="A8" /&gt;
    &lt;label for="A8"&gt;A8&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|6' id="A7" /&gt;
    &lt;label for="A7"&gt;A7&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|5' id="A6" /&gt;
    &lt;label for="A6"&gt;A6&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|4' id="A5" /&gt;
    &lt;label for="A5"&gt;A5&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|3' id="A4" /&gt;
    &lt;label for="A4"&gt;A4&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|2' id="A3" /&gt;
    &lt;label for="A3"&gt;A3&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|1' id="A2" /&gt;
    &lt;label for="A2"&gt;A2&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|0' id="A1" /&gt;
    &lt;label for="A1"&gt;A1&lt;/label&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>