public function makeOptionList($items, callable $optionArgs, array &$valuesRendered = [])
	{
		$ret = [];
		foreach ($items as $value => $caption) {
			if (is_int($value)) {
				$value = (string)$value;
			}

			if (is_array($caption)) {
				// subgroup
				$option = Html::el('optgroup', ['label' => $value]);

				// options within the group
				$nested = $this->makeOptionList($caption, $optionArgs, $valuesRendered);

				foreach ($nested as $item) {
					$option->addHtml($item);
				}
			}
			else {
				if (in_array($value, $valuesRendered)) {
					throw new InvalidArgumentException("Value '$value' is used multiple times.");
				}
				$valuesRendered[] = $value;

				// normal option
				$option = Html::el('option',
					array_merge(['value' => (string)$value], $optionArgs($value, $caption)));
				$option->setText($caption);
			}
			$ret[] = $option;
		}

		return $ret;
	}
public function makeOptionList($items, callable $optionArgs, array &$valuesRendered = [])
	{
		$ret = [];
		foreach ($items as $value => $caption) {
			if (is_int($value)) {
				$value = (string)$value;
			}

			if (is_array($caption)) {
				// subgroup
				$option = Html::el('optgroup', ['label' => $value]);

				// options within the group
				$nested = $this->makeOptionList($caption, $optionArgs, $valuesRendered);

				foreach ($nested as $item) {
					$option->addHtml($item);
				}
			}
			else {
				if (in_array($value, $valuesRendered)) {
					throw new InvalidArgumentException("Value '$value' is used multiple times.");
				}
				$valuesRendered[] = $value;

				// normal option
				$option = Html::el('option',
					array_merge(['value' => (string)$value], $optionArgs($value, $caption)));
				$option->setText($caption);
			}
			$ret[] = $option;
		}

		return $ret;
	}
public function makeOptionList ( $ items , callable $ optionArgs , array & $ valuesRendered = [ ] ) { $ ret = [ ] ; foreach ( $ items as $ value => $ caption ) { if ( is_int ( $ value ) ) { $ value = ( string ) $ value ; } if ( is_array ( $ caption ) ) { // subgroup $ option = Html :: el ( 'optgroup' , [ 'label' => $ value ] ) ; // options within the group $ nested = $ this -> makeOptionList ( $ caption , $ optionArgs , $ valuesRendered ) ; foreach ( $ nested as $ item ) { $ option -> addHtml ( $ item ) ; } } else { if ( in_array ( $ value , $ valuesRendered ) ) { throw new InvalidArgumentException ( "Value '$value' is used multiple times." ) ; } $ valuesRendered [ ] = $ value ; // normal option $ option = Html :: el ( 'option' , array_merge ( [ 'value' => ( string ) $ value ] , $ optionArgs ( $ value , $ caption ) ) ) ; $ option -> setText ( $ caption ) ; } $ ret [ ] = $ option ; } return $ ret ; }
Makes array of &lt;option&gt;. Can handle associative arrays just fine. Checks for duplicate values.
@param array    $items
@param callable $optionArgs     takes ($value,$caption) and spits out an array of &lt;option&gt;
attributes
@param array    $valuesRendered for internal use. Do not change.
@return array
@throws InvalidArgumentException when $items have multiple of the same values
Makes array of &lt ; option&gt ; . Can handle associative arrays just fine . Checks for duplicate values .