W3cubDocs

/Drupal 8

protected static function OptGroup::doFlattenOptions

protected static OptGroup::doFlattenOptions(array $array, array &$options)

Iterates over an array building a flat array with duplicate keys removed.

This function also handles cases where objects are passed as array values.

Parameters

array $array: The form options array to process.

array $options: The array of flattened options.

File

core/lib/Drupal/Core/Form/OptGroup.php, line 39

Class

OptGroup
Provides helpers for HTML option groups.

Namespace

Drupal\Core\Form

Code

protected static function doFlattenOptions(array $array, array &$options) {
  foreach ($array as $key => $value) {
    if (is_object($value) && isset($value->option)) {
      static::doFlattenOptions($value->option, $options);
    }
    elseif (is_array($value)) {
      static::doFlattenOptions($value, $options);
    }
    else {
      $options[$key] = $value;
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!OptGroup.php/function/OptGroup::doFlattenOptions/8.1.x