xref: /webtrees/resources/views/components/select.phtml (revision 4a9a60957058ca2a34e30a0d6f783e1540606590)
1<?php
2
3declare(strict_types=1);
4
5/**
6 * @var string|null   $class
7 * @var string|null   $id
8 * @var string        $name
9 * @var mixed         $selected
10 * @var array<string> $options
11 * @var string|null   $aria_label
12 */
13
14?>
15
16<select
17    class="form-select <?= $class ?? '' ?>"
18    name="<?= e($name) ?>"
19    id="<?= e($id ?? $name) ?>"
20    <?= is_array($selected) ? 'multiple="multiple"' : '' ?>
21    aria-label="<?= e($aria_label ?? '') ?>"
22
23>
24    <?php foreach ($options as $key => $value) : ?>
25        <option value="<?= e((string) $key) ?>"<?= (is_array($selected) ? in_array($key, $selected, false) : (string) $key === (string) $selected) ?  ' selected="selected"' : '' ?>>
26            <?= $value === '' ? '&nbsp;' : e($value) ?>
27        </option>
28    <?php endforeach ?>
29</select>
30