-4
I need to create a function to compare value and mark radio buttom.
$checklistIni = unserialize($row_rsRegistros['checklistIni']);
$a = join(',', array_values($checklistIni));
function compara($valor) {
$array = explode(",", $a);
if(in_array($valor, $checklistIni)) {
return "checked";
}
}
And then use right where I need to make the comparison.
<tbody>
<tr>
<td class="texto-branco">Documento</td>
<td><label><input value="tem" <?php echo compara("tem"); ?> name="checklistFim0" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="nao" <?php echo compara("nao"); ?> name="checklistFim0" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="ava" <?php echo compara("ava"); ?> name="checklistFim0" class="checklistFim" type="radio" /><span></span></label></td>
</tr>
<tr><td class="texto-branco"> Manual </td>
<td><label><input value="tem" <?php echo compara("tem"); ?> name="checklistFim1" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="nao" <?php echo compara("nao"); ?> name="checklistFim1" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="ava" <?php echo compara("ava"); ?> name="checklistFim1" class="checklistFim" type="radio" /><span></span></label></td>
</tr>
<tr><td class="texto-branco">Vidro eletrico </td>
<td><label><input value="tem" <?php echo compara("tem"); ?> name="checklistFim2" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="nao" <?php echo compara("nao"); ?> name="checklistFim2" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="ava" <?php echo compara("ava"); ?> name="checklistFim2" class="checklistFim" type="radio" /><span></span></label></td>
</tr>
<tr><td class="texto-branco">Radio/CD </td>
<td><label><input value="tem" <?php echo compara("tem"); ?> name="checklistFim3" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="nao" <?php echo compara("nao"); ?> name="checklistFim3" class="checklistFim" type="radio" /><span></span></label></td>
<td><label><input value="ava" <?php echo compara("ava"); ?> name="checklistFim3" class="checklistFim" type="radio" /><span></span></label></td>
</tr>
</tbody>
something like
echo $key1 . ","
?– Ricardo Pontual
Clear example of XY problem. There is no justification for you from a array, generate a string, to then pass the value (as global variable?) to a function that will convert back to array. The solution seems very ineffective and you can solve your problem by preventing it from happening, making it more plausible.
– Woss