This question was submitted a couple of years ago, but maybe my answer will benefit someone. I was working on a form and ended up with this solution:
Code:
$checkbox_data = [
'name' => 'name',
'value' => '1',
'checked' => set_checkbox('name', '1') != '' ? true : false
];
Notice how "checked" is set. The set_checkbox method returns either ' checked="checked"' or an empty string. We can check it and set true or false. After that in view we can use this:
Code:
<?= form_checkbox(checkbox_data) ?>