method buildOptions documentation in bbn\X

Returns the HTML code for creating the <option> tag(s) based on an array.

If the array is indexed, the index will be used as value

Example

X::buildOptions(['yes', 'no']); // string "" X::buildOptions(['yes', 'no'], 'no'); // string "" X::buildOptions(['yes', 'no'], 'no', 'LabelForEmpty'); // string "" X::dump(X::buildOptions([3 => "Allison", 4 => "Mike", 5 => "Andrew"], 5, 'Who?')); // string "" function(array $values, $selected = '', $empty_label = false) { $r = ''; if ($empty_label !== false) { $r .= ''; } $is_assoc = self::isAssoc($values); foreach ($values as $k => $v) { if (\is_array($v) && \count($v) == 2) { $value = $v[0]; $title = $v[1]; } elseif (!isset($values[0]) && $is_assoc) { $value = $k; $title = $v; } else { $value = $title = $v; } if (isset($value,$title)) { $r .= ''; } unset($value,$title); } return $r; }

Returns the HTML code for creating the <option> tag(s) based on an array. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.