0
Good evening. How do I use foreach suns to check if the names are equal and so leave them with selected.
Follows the returns of the variables:
$risco_e =
Array
(
[0] => Postura Inadequada
[1] => Postura Inadequada por tempo Indetermidado
)
$risco_ergonomico =
Array
(
[0] => stdClass Object
(
[idRiscoErgonomico] =>; 5
[riscoErgonomico_Nome] =>; Esforço Fisico
)
[1] => stdClass Object
(
[idRiscoErgonomico] =>; 1
[riscoErgonomico_Nome] =>; Não Exposto
)
[2] => stdClass Object
(
[idRiscoErgonomico] =>; 2
[riscoErgonomico_Nome] =>; Odontologos
)
[3] => stdClass Object
(
[idRiscoErgonomico] =>; 3
[riscoErgonomico_Nome] =>; Posições Encomodas
)
[4] => stdClass Object
(
[idRiscoErgonomico] =>; 6
[riscoErgonomico_Nome] =>; Postura Inadequada
)
[5] => stdClass Object
(
[idRiscoErgonomico] =>; 4
[riscoErgonomico_Nome] =>; Postura Inadequada por tempo Indetermidado
)
)
I tried so and kind that worked, the same values are selected, but all are duplicated, as shown in the following photo:
<select>
<?php
str = trim($result->setor_RiscoErgonomico, ',');
$risco_e = explode(',', $str);
foreach ($risco_ergonomico as $riscoErgonomico)
{
foreach ($risco_e as $re)
{ ?>
<option <?=$re == $riscoErgonomico->riscoErgonomico_Nome ? "selected" : ""?>><?=$riscoErgonomico->riscoErgonomico_Nome?></option>
<?php }
}
?>
</select>
I don’t understand your doubt
– novic
Normally it was only to appear one name of each risk, but when performing the two foreach are being duplicated the values.
– José Luis