{"id":1345,"date":"2016-08-18T14:14:26","date_gmt":"2016-08-18T12:14:26","guid":{"rendered":"https:\/\/www.speich.net\/articles\/?p=1345"},"modified":"2019-10-06T09:53:12","modified_gmt":"2019-10-06T07:53:12","slug":"php-how-to-sort-a-nodelist-by-element-attribute","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2016\/08\/18\/php-how-to-sort-a-nodelist-by-element-attribute\/","title":{"rendered":"PHP: How to sort a NodeList by element attribute"},"content":{"rendered":"\n<pre><code class=\"language-php\">$elements = iterator_to_array($nodeList);\nusort($elements, function($a, $b) {\n  return (int) $b-&gt;getAttribute('someAttribute') - (int) $a-&gt;getAttribute('someAttribute');\n});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$elements = iterator_to_array($nodeList); usort($elements, function($a, $b) { return (int) $b-&gt;getAttribute(&#8216;someAttribute&#8217;) &#8211; (int) $a-&gt;getAttribute(&#8216;someAttribute&#8217;); });<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[234,236],"class_list":["post-1345","post","type-post","status-publish","format-standard","hentry","category-php","tag-domdocument","tag-xml","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=1345"}],"version-history":[{"count":3,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1345\/revisions"}],"predecessor-version":[{"id":1654,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1345\/revisions\/1654"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=1345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=1345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=1345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}