PHP: How to sort a NodeList by element attribute

$elements = iterator_to_array($nodeList); usort($elements, function($a, $b) { return (int) $b->getAttribute(‘someAttribute’) – (int) $a->getAttribute(‘someAttribute’); });