Order object simplexml_load_file by field of this.

Posted by ronsandova on Stack Overflow See other posts from Stack Overflow or by ronsandova
Published on 2010-04-07T07:06:11Z Indexed on 2010/04/07 7:13 UTC
Read the original article Hit count: 232

Filed under:
|
|

Hi i have a problems with simplexml_load_file, i'm not pretty sure how to do to order my array by a $item->padre.

I need to do foreach and order by $item->padre.=, i don't know how to do this.

function create_sitemap($sitemap){

$xml = file_exists('sitemap.xml') ? $xml = simplexml_load_file('sitemap.xml'): exit('Failed to open sitemal.xml.');

$xml = uasort($xml, function($a,$b){ return strcmp($a->padre, $b->padre); });

foreach ($xml->url as $item) {

echo "

" . $item->loc. "

"; echo "

" . $item->padre . "

";

}

}

Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about php5