RearrangeFilter::arrayKeyPlus

public static RearrangeFilter::arrayKeyPlus($array)

Adds one to each key of an array.

For example array(0 => 'foo') would be array(1 => 'foo').

Parameters

array $array: The array to increment keys on.

Return value

array The array with incremented keys.

File

core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php, line 340

Class

RearrangeFilter
Provides a rearrange form for Views filters.

Namespace

Drupal\views_ui\Form\Ajax

Code

public static function arrayKeyPlus($array) {
  $keys = array_keys($array);
  // Sort the keys in reverse order so incrementing them doesn't overwrite any
  // existing keys.
  rsort($keys);
  foreach ($keys as $key) {
    $array[$key + 1] = $array[$key];
    unset($array[$key]);
  }
  // Sort the keys back to ascending order.
  ksort($array);
  return $array;
}
doc_Drupal
2016-10-29 09:36:43
Comments
Leave a Comment

Please login to continue.