From 45e57367d3f9571fde2b82fa2fd8126469ba6db6 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 28 Nov 2024 13:18:58 +0300 Subject: [PATCH] create option trait update: value can be array already --- src/traits/CreateOption.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/traits/CreateOption.php b/src/traits/CreateOption.php index 0ba5071..ffc3f15 100755 --- a/src/traits/CreateOption.php +++ b/src/traits/CreateOption.php @@ -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 .= ""; + if (is_array($value)) { + foreach ($options as $val => $title) { + $selected = in_array($title, $value) ? "selected" : ""; + $optionsString .= ""; + } + } else { + foreach ($options as $val => $title) { + $selected = (int)$value === $val ? "selected" : ""; + $optionsString .= ""; + } } + return $optionsString; } } \ No newline at end of file