You are here

protected function ViewTestBase::orderResultSet in Drupal 8

Same name in this branch
  1. 8 core/modules/views/src/Tests/ViewTestBase.php \Drupal\views\Tests\ViewTestBase::orderResultSet()
  2. 8 core/modules/views/tests/src/Functional/ViewTestBase.php \Drupal\Tests\views\Functional\ViewTestBase::orderResultSet()
Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/ViewTestBase.php \Drupal\Tests\views\Functional\ViewTestBase::orderResultSet()

Orders a nested array containing a result set based on a given column.

Parameters

array $result_set: An array of rows from a result set, with each row as an associative array keyed by column name.

string $column: The column name by which to sort the result set.

bool $reverse: (optional) Boolean indicating whether to sort the result set in reverse order. Defaults to FALSE.

Return value

array The sorted result set.

File

core/modules/views/tests/src/Functional/ViewTestBase.php, line 82

Class

ViewTestBase
Defines a base class for Views testing in the full web test environment.

Namespace

Drupal\Tests\views\Functional

Code

protected function orderResultSet($result_set, $column, $reverse = FALSE) {
  $order = $reverse ? -1 : 1;
  usort($result_set, function ($a, $b) use ($column, $order) {
    if ($a[$column] == $b[$column]) {
      return 0;
    }
    return $order * ($a[$column] < $b[$column] ? -1 : 1);
  });
  return $result_set;
}