function element_sort

Sorts a structured array by '#weight' property.

Callback for uasort() within element_children().

Parameters

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

$b: Second item for comparison.

2 string references to 'element_sort'
element_children in drupal/core/includes/common.inc
Identifies the children of an element array, optionally sorted by weight.
toolbar_pre_render in drupal/core/modules/toolbar/toolbar.module
Builds the Toolbar as a structured array ready for drupal_render().

File

drupal/core/includes/common.inc, line 5191
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;
}