function SortArray::sortByKeyRecursive

Sorts an array recursively, by key, alphabetically.

Parameters

array $data: The array to sort, passed by reference.

4 calls to SortArray::sortByKeyRecursive()
ConfigConfigurator::__construct in core/lib/Drupal/Core/Recipe/ConfigConfigurator.php
ContentExportTest::testExportContent in core/tests/Drupal/FunctionalTests/DefaultContent/ContentExportTest.php
Ensures that all imported content can be exported properly.
ResourceTestBase::recursiveKSort in core/modules/rest/tests/src/Functional/ResourceTestBase.php
Recursively sorts an array by key.
SortArrayTest::testRecursiveSortByKey in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests sorting arrays recursively by key.

File

core/lib/Drupal/Component/Utility/SortArray.php, line 134

Class

SortArray
Provides generic array sorting helper methods.

Namespace

Drupal\Component\Utility

Code

public static function sortByKeyRecursive(array &$data) : void {
  // If the array is a list, it is by definition already sorted.
  if (!array_is_list($data)) {
    ksort($data);
  }
  foreach ($data as &$value) {
    if (is_array($value)) {
      self::sortByKeyRecursive($value);
    }
  }
}

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