21 lines
499 B
PHP
21 lines
499 B
PHP
|
<?php
|
||
|
|
||
|
namespace itguild\forms\form\traits;
|
||
|
|
||
|
trait CreateOption
|
||
|
{
|
||
|
/**
|
||
|
* @param array $options
|
||
|
* @param $value
|
||
|
* @return string
|
||
|
*/
|
||
|
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>";
|
||
|
}
|
||
|
return $optionsString;
|
||
|
}
|
||
|
}
|