element_children
- Versions
- 4.7 – 6
element_children($element)- 7
element_children(&$elements, $sort = FALSE)
Return the children of an element, optionally sorted by weight.
Parameters
$elements The element to be sorted.
$sort Boolean to indicate whether the children should be sorted by weight.
Return value
The array keys of the element's children.
Code
includes/common.inc, line 5295
<?php
function element_children(&$elements, $sort = FALSE) {
// Do not attempt to sort elements which have already been sorted.
$sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
// Filter out properties from the element, leaving only children.
$children = array();
$sortable = FALSE;
foreach ($elements as $key => $value) {
if ($key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
$sortable = TRUE;
}
}
}
// Sort the children if necessary.
if ($sort && $sortable) {
uasort($children, 'element_sort');
// Put the sorted children back into $elements in the correct order, to
// preserve sorting if the same element is passed through
// element_children() twice.
foreach ($children as $key => $child) {
unset($elements[$key]);
$elements[$key] = $child;
}
$elements['#sorted'] = TRUE;
}
return array_keys($children);
}
?>Login or register to post comments 