function OptGroup::doFlattenOptions

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Form/OptGroup.php \Drupal\Core\Form\OptGroup::doFlattenOptions()
  2. 10 core/lib/Drupal/Core/Form/OptGroup.php \Drupal\Core\Form\OptGroup::doFlattenOptions()
  3. 11.x core/lib/Drupal/Core/Form/OptGroup.php \Drupal\Core\Form\OptGroup::doFlattenOptions()

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.

1 call to OptGroup::doFlattenOptions()
OptGroup::flattenOptions in core/lib/Drupal/Core/Form/OptGroup.php
Allows PHP array processing of multiple select options with the same value.

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;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.