Good afternoon friends! Please help in writing the code. In this example, the checked will be inserted 3 times in a row. And what if instead of "3", there will be "6"? checked will be inserted 2 times. What to change, so that all selected checkboxes appear?

$ der is an array of checkboxes that are checked;

$ reh is all checkboxes

$der = array(1,2,3); $reh = array(text1, text2, text3, text4, text5, text6); $table = "<table><tbody><tr>"; $i = 0; foreach($reh as $a => $v) { if ($v[ad] == 'text'){ $table .= "<td style='width: 20%;'> <label class='checkbox'> <input name='derk[]' type='checkbox' value='".$v[id]."'> <i></i> <span style='font-size:11px;'>".$v[ad]."</span></label></td>"; }else{ $table .= "<td style='width: 20%;'> <label class='checkbox'> <input name='derk[]' type='checkbox' value='".$v[id]."'"; //знаю ошибка в след. 3 строках if ($v[id] == $der[$i]) {$table .= " checked=''>";} else{$table .= ">";} $i++; $table .= "<i></i> ".$v[ad]."</label></td>"; } if(($a+1) % 5 == 0) $table .= "</tr><tr>"; } $table .= "</tr></tbody></table>"; echo $table; 
  • If you specify a programming language in the tags, the chances of getting an answer will increase. - German Borisov
  • Thanks for the info - Jabbar Guliyev
  • text1, text2 , $v[id] , $v[ad] what is all this with you? lost quotes or $ ? - teran
  • Your whole problem is that you interfere with the logic of the submission. Get rid of that. Prepare a data model and use templates. The code will become simple and clear. - teran
  • quotes forgotten in all mentioned places. The main thing here is how to write code to display checked = '' where necessary - Jabbar Guliyev

0