function RearrangeFilter::arrayKeyPlus
Same name in other branches
- 8.9.x core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php \Drupal\views_ui\Form\Ajax\RearrangeFilter::arrayKeyPlus()
- 10 core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php \Drupal\views_ui\Form\Ajax\RearrangeFilter::arrayKeyPlus()
- 11.x core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php \Drupal\views_ui\Form\Ajax\RearrangeFilter::arrayKeyPlus()
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.
2 calls to RearrangeFilter::arrayKeyPlus()
- RearrangeFilter::submitForm in core/
modules/ views_ui/ src/ Form/ Ajax/ RearrangeFilter.php - Form submission handler.
- RearrangeFilterTest::testStaticMethods in core/
modules/ views_ui/ tests/ src/ Unit/ Form/ Ajax/ RearrangeFilterTest.php - Tests static methods.
File
-
core/
modules/ views_ui/ src/ Form/ Ajax/ RearrangeFilter.php, line 344
Class
- RearrangeFilter
- Provides a rearrange form for Views filters.
Namespace
Drupal\views_ui\Form\AjaxCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.