3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getgeneralSpecifications() { return [ ['sp_id' => 1, 'specifications_name' => 'example 1'], ['sp_id' => 2, 'specifications_name' => 'example 2'], ['sp_id' => 3, 'specifications_name' => 'example 3'], ['sp_id' => 4, 'specifications_name' => 'example 4'], ['sp_id' => 5, 'specifications_name' => 'example 5'], ['sp_id' => 6, 'specifications_name' => 'example 6'], ]; } $checked = explode(',', '1,2,4'); echo "<ul>"; foreach (getgeneralSpecifications() as $row) { printf( '<li> <label>%s</label> <div class="form-check"> <input class="form-check-input custom-checkbox generalsinglecheck" type="checkbox" value="%d" name="general_specification[]" %s> </div> </li>', $row['specifications_name'], $row['sp_id'], in_array($row['sp_id'], $checked) ? 'checked' : '' ); } echo "</ul>";

preferences:
27.43 ms | 406 KiB | 5 Q