I have an array in PHP that is the values selected from the checkbox, which were obtained by $ _GET:
$_GET['selecionados'] = array(2) {
[0]=> string(1) "a"
[1]=> string(1) "b"
}
Here are the chekboxes:
foreach($selecoes = $check){
echo '<input type="checkbox" value="'.$check->valor.'" name="selecionados[]" id="'.$check->valor.'">
}
it prints:
<input type="checkbox" value="a" name="selecionados[]" id="a">
<input type="checkbox" value="b" name="selecionados[]" id="b">
<input type="checkbox" value="c" name="selecionados[]" id="c">
<input type="checkbox" value="d" name="selecionados[]" id="d">
I need if the selected value is in $ _GET ['selected'], it is marked as checked. this example would look like this:
<input type="checkbox" value="a" name="selecionados[]" id="a" checked>
<input type="checkbox" value="b" name="selecionados[]" id="b" checked>
<input type="checkbox" value="c" name="selecionados[]" id="c">
<input type="checkbox" value="d" name="selecionados[]" id="d">
How to do it? I imagine it's using str_replace, but I do not know exactly how.