element_sort

6 common.inc element_sort($a, $b)
7 common.inc element_sort($a, $b)
8 common.inc element_sort($a, $b)

Function used by uasort to sort structured arrays by weight.

1 string reference to 'element_sort'

File

includes/common.inc, line 6157
Common functions that many Drupal modules will need to reference.

Code

function element_sort($a, $b) {
  $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0;
  $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0;
  if ($a_weight == $b_weight) {
    return 0;
  }
  return ($a_weight < $b_weight) ? -1 : 1;
}

Comments

A usage example for this can

A usage example for this can be found on the Drupal 6 documentation page for this function (it works identically as in Drupal 7).

Login or register to post comments