function SortArray::sortByWeightElement

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/SortArray.php \Drupal\Component\Utility\SortArray::sortByWeightElement()
  2. 8.9.x core/lib/Drupal/Component/Utility/SortArray.php \Drupal\Component\Utility\SortArray::sortByWeightElement()
  3. 11.x core/lib/Drupal/Component/Utility/SortArray.php \Drupal\Component\Utility\SortArray::sortByWeightElement()

Sorts a structured array by the 'weight' element.

Note that the sorting is by the 'weight' array element, not by the render element property '#weight'.

Callback for uasort().

Parameters

array $a: First item for comparison. The compared items should be associative arrays that optionally include a 'weight' element. For items without a 'weight' element, a default value of 0 will be used.

array $b: Second item for comparison.

Return value

int The comparison result for uasort().

2 calls to SortArray::sortByWeightElement()
Finder::__construct in core/lib/Drupal/Core/DefaultContent/Finder.php
SortArrayTest::testSortByWeightElement in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByWeightElement() input against expected output.

File

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

Class

SortArray
Provides generic array sorting helper methods.

Namespace

Drupal\Component\Utility

Code

public static function sortByWeightElement(array $a, array $b) {
    return static::sortByKeyInt($a, $b, 'weight');
}

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