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');
});

Leave a Reply

Your email address will not be published. Required fields are marked *