function SortArrayTest::testRecursiveSortByKey

Tests sorting arrays recursively by key.

File

core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php, line 341

Class

SortArrayTest
Tests the SortArray component.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRecursiveSortByKey() : void {
  // Indexed arrays are sorted already.
  $array = [
    'one',
    'two',
    'three',
  ];
  SortArray::sortByKeyRecursive($array);
  $this->assertSame([
    'one',
    'two',
    'three',
  ], $array);
  $array = [
    'one key' => [
      'one',
      'two',
      'three',
    ],
    'another key' => [
      'b' => 'see',
      'a' => 'bee',
    ],
  ];
  SortArray::sortByKeyRecursive($array);
  $this->assertSame($array, [
    'another key' => [
      'a' => 'bee',
      'b' => 'see',
    ],
    'one key' => [
      'one',
      'two',
      'three',
    ],
  ]);
}

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