You are here

protected function RequestTest::nestedKsort in OpenAPI 8

Sorts a nested array with ksort().

Parameters

array $array: The nested array to sort.

1 call to RequestTest::nestedKsort()
RequestTest::requestOpenApiJson in tests/src/Functional/RequestTest.php
Makes OpenAPI request and checks the response.

File

tests/src/Functional/RequestTest.php, line 480

Class

RequestTest
Tests requests OpenAPI routes.

Namespace

Drupal\Tests\openapi\Functional

Code

protected function nestedKsort(array &$array) {
  if ($this
    ->isAssocArray($array)) {
    ksort($array);
  }
  else {
    usort($array, function ($a, $b) {
      if (isset($a['name']) && isset($b['name'])) {
        return strcmp($a['name'], $b['name']);
      }
      return -1;
    });
  }
  foreach ($array as &$item) {
    if (is_array($item)) {
      $this
        ->nestedKsort($item);
    }
  }
}