create option trait update: value can be array already
This commit is contained in:
parent
ddb17cc473
commit
45e57367d3
@ -12,10 +12,18 @@ trait CreateOption
|
||||
public function createOption(array $options, $value = null): string
|
||||
{
|
||||
$optionsString = "";
|
||||
foreach ($options as $val => $title){
|
||||
$selected = (int)$value === $val ? "selected" : "";
|
||||
$optionsString .= "<option $selected value='$val'>$title</option>";
|
||||
if (is_array($value)) {
|
||||
foreach ($options as $val => $title) {
|
||||
$selected = in_array($title, $value) ? "selected" : "";
|
||||
$optionsString .= "<option $selected value='$val'>$title</option>";
|
||||
}
|
||||
} else {
|
||||
foreach ($options as $val => $title) {
|
||||
$selected = (int)$value === $val ? "selected" : "";
|
||||
$optionsString .= "<option $selected value='$val'>$title</option>";
|
||||
}
|
||||
}
|
||||
|
||||
return $optionsString;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user