function SortArray::sortByKeyInt

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

Sorts an integer array item by an arbitrary key.

Parameters

array $a: First item for comparison.

array $b: Second item for comparison.

string $key: The key to use in the comparison.

Return value

int The comparison result for uasort().

3 calls to SortArray::sortByKeyInt()
SortArray::sortByWeightElement in core/lib/Drupal/Component/Utility/SortArray.php
Sorts a structured array by the 'weight' element.
SortArray::sortByWeightProperty in core/lib/Drupal/Component/Utility/SortArray.php
Sorts a structured array by '#weight' property.
WidgetBase::extractFormValues in core/lib/Drupal/Core/Field/WidgetBase.php
Extracts field values from submitted form values.

File

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

Class

SortArray
Provides generic array sorting helper methods.

Namespace

Drupal\Component\Utility

Code

public static function sortByKeyInt($a, $b, $key) {
    $a_weight = is_array($a) && isset($a[$key]) ? $a[$key] : 0;
    $b_weight = is_array($b) && isset($b[$key]) ? $b[$key] : 0;
    return $a_weight <=> $b_weight;
}

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