private static function sortByWeights(array &$array) {
    uasort($array, function ($a, $b) {
      $a_weight = isset($a['weight']) ? $a['weight'] : 0;
      $b_weight = isset($b['weight']) ? $b['weight'] : 0;

      if ($a_weight == $b_weight) {
        return ($a['label'] > $b['label']) ? 1 : -1;
      }
      return ($a_weight > $b_weight) ? 1 : -1;
    });
  }
private static function sortByWeights(array &$array) {
    uasort($array, function ($a, $b) {
      $a_weight = isset($a['weight']) ? $a['weight'] : 0;
      $b_weight = isset($b['weight']) ? $b['weight'] : 0;

      if ($a_weight == $b_weight) {
        return ($a['label'] > $b['label']) ? 1 : -1;
      }
      return ($a_weight > $b_weight) ? 1 : -1;
    });
  }
private static function sortByWeights ( array & $ array ) { uasort ( $ array , function ( $ a , $ b ) { $ a_weight = isset ( $ a [ 'weight' ] ) ? $ a [ 'weight' ] : 0 ; $ b_weight = isset ( $ b [ 'weight' ] ) ? $ b [ 'weight' ] : 0 ; if ( $ a_weight == $ b_weight ) { return ( $ a [ 'label' ] > $ b [ 'label' ] ) ? 1 : - 1 ; } return ( $ a_weight > $ b_weight ) ? 1 : - 1 ; } ) ; }
Returns a sorting function to sort an array by weights.

If an array element doesn't provide a weight, it will be set to 0.
If two elements have the same weight, they are sorted by label.

@param array $array
The array to be sorted.
Returns a sorting function to sort an array by weights .