You are here

public static function SortArray::sortByKeyString in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Utility/SortArray.php \Drupal\Component\Utility\SortArray::sortByKeyString()
  2. 9 core/lib/Drupal/Component/Utility/SortArray.php \Drupal\Component\Utility\SortArray::sortByKeyString()

Sorts a string 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().

File

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

Class

SortArray
Provides generic array sorting helper methods.

Namespace

Drupal\Component\Utility

Code

public static function sortByKeyString($a, $b, $key) {
  $a_title = is_array($a) && isset($a[$key]) ? $a[$key] : '';
  $b_title = is_array($b) && isset($b[$key]) ? $b[$key] : '';
  return strnatcasecmp($a_title, $b_title);
}