function SortArray::sortByWeightProperty

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

Sorts a structured array by '#weight' property.

Callback for uasort().

Parameters

array $a: First item for comparison. The compared items should be associative arrays that optionally include a '#weight' key.

array $b: Second item for comparison.

Return value

int The comparison result for uasort().

1 call to SortArray::sortByWeightProperty()
SortArrayTest::testSortByWeightProperty in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByWeightProperty() input against expected output.

File

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

Class

SortArray
Provides generic array sorting helper methods.

Namespace

Drupal\Component\Utility

Code

public static function sortByWeightProperty($a, $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.