function _file_sort_array_by_weight in D7 Media 7
Helper function to sort an array by the value of each item's 'weight' key, while preserving relative order of items that have equal weight.
3 calls to _file_sort_array_by_weight()
- file_info_file_types in file_entity/
file_entity.file_api.inc - Returns information about file types from hook_file_type_info().
- file_info_formatter_types in file_entity/
file_entity.file_api.inc - Returns information about file formatters from hook_file_formatter_info().
- file_view_file in file_entity/
file_entity.file_api.inc - Generate an array for rendering just the file portion of a file entity.
File
- file_entity/
file_entity.file_api.inc, line 377 - API extensions of Drupal core's file.inc.
Code
function _file_sort_array_by_weight(&$a) {
$i = 0;
foreach ($a as $key => $item) {
if (!isset($a[$key]['weight'])) {
$a[$key]['weight'] = 0;
}
$original_weight[$key] = $a[$key]['weight'];
$a[$key]['weight'] += $i / 1000;
$i++;
}
uasort($a, 'drupal_sort_weight');
foreach ($a as $key => $item) {
$a[$key]['weight'] = $original_weight[$key];
}
}