[Solved] Set checked checkbox from array [closed]


Try this code –

<?php
$all_data = ["admin","member","editor"];
$selected = ["admin","member"];

foreach($all_data as $value) {
  $checked = in_array($value, $selected) ? 'checked="checked"' : '';
  echo '<input type="checkbox" name="chk[]" value="' . $value .'" ' . $checked . '>';
}
?>

solved Set checked checkbox from array [closed]