I have a list of checkbox
in which the user selects and sends the form
, they are saved in a array
and put them in a data table, these are saved as for example: Chino, Árabe, Español
.
By sending a select
to be able to show the configuration that the user selected, I need to access each specific value, that is, if the user selects for example the field Árabe
this is placed in checked
, at reload the page.
I tried it like this but it worked for me because it sends me Warnigs
if it selects several languages or less languages than what happened to it and the idea is to be dynamic.
// $data_talk el valor que devuelve la tabla.
list($region) = explode(",", trim($data_talk->idiomas,0));
Also try this:
$array = explode(",",trim($data_talk->idiomas));
foreach($array as $data => $key){
print_r($key);
}
Returns the languages of the table, but I want to access each field to evaluate conditional if
if in all those values is the language to print echo "checked=checked"
;
<label for="4">Alemán</label>
</li>
<li class="check">
<input id="8" class="wicket-id56" <?php //if here ?> name="language[]" value="Arabe" type="checkbox">
<label for="8">Árabe</label>
</li>
<li class="check">
<input id="2" class="wicket-id56" name="language[]" value="Catalán" type="checkbox">
<label for="2">Catalán</label>
</li>
<li class="check">
<input id="9" class="wicket-id56" name="language[]" value="Checo" type="checkbox">
<label for="9">Checo</label>
</li>
<li class="check">
<input id="10" class="wicket-id56" name="language[]" value="Chino" type="checkbox">
<label for="10">Chino</label>
</li>
<li class="check">
<input id="30" class="wicket-id56" name="language[]" value="Coreano" type="checkbox">
<label for="30">Coreano</label>
</li>
<li class="check">
<input id="11" class="wicket-id56" name="language[]" value="Croata" type="checkbox">
<label for="11">Croata</label>
</li>
<li class="check">
<input id="12" class="wicket-id56" name="language[]" value="Danés" type="checkbox">
<label for="12">Danés</label>
</li>
//Recibe los checkbox y los inserto en otra función a la tabla simplemente
public function readData($language){
if (is_array($language)) {
$selected = '';
$num_countries = count($language);
$current = 0;
foreach ($language as $key => $value) {
if ($current != $num_countries-1)
$selected .= $value.', ';
else
$selected .= $value.'.';
$current++;
}
}
else {
$selected = 'Debes seleccionar un país';
}
return $selected;
}