<?php
$xml=simplexml_load_string(<<<XML
<?xml version="1.0"?>
<products><product><product_code>0084064919005</product_code><name>Spy Men's Hielo Sunglasses</name><stock>1</stock><regular_price>94.95</regular_price><sale_price>44.93</sale_price><brand>Spy Optic Inc </brand><gender/><category>Sunglasses</category><product_description>The Spy Men's Hielo Sunglasses are a classic hit maker. The frames are custom built out of high quality propionate, a lightweight durable material. An 8 base curve ARC lens gives you perfect clarity without distortion and gives you 100% UV protection.</product_description><buy_url>http://www.sunandski.com/ProductDetails.asp?ProductCode=0084064919005</buy_url><large_image_url>imgs/products/lrg/0084064919005.jpg</large_image_url><remote_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919005-2T.jpg</remote_image_url><small_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919005-1.jpg</small_image_url><size/><savings>53</savings></product><product><product_code>0084064919010</product_code><name>Spy Men's Hsx Sunglasses</name><stock>10</stock><regular_price>104.95</regular_price><sale_price>49.93</sale_price><brand>Spy Optic Inc </brand><gender/><category>Sunglasses</category><product_description>The Spy Men's Hsx Sunglasses is packed with all the features and style you expect from the Spy line of sunglasses. The frames are made out of ultra-lightweight and durable Grilamid. An 8x4-base toric arc lenses give you vision without distortion. These glasses are scratch and impact resistant so that they will be your favorite for a long time to come.</product_description><buy_url>http://www.sunandski.com/ProductDetails.asp?ProductCode=0084064919010</buy_url><large_image_url>imgs/products/lrg/0084064919010.jpg</large_image_url><remote_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919010-2T.jpg</remote_image_url><small_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919010-1.jpg</small_image_url><size/><savings>53</savings></product><product><product_code>0084064919011</product_code><name>Spy Men's Hsx Sunglasses</name><stock>6</stock><regular_price>149.95</regular_price><sale_price>69.93</sale_price><brand>Spy Optic Inc </brand><gender/><category>Sunglasses</category><product_description>The Spy Men's Hsx Sunglasses are made from lightweight durable Grilamid. It has 8x4 base Toric Arc Lenses give you superior vision without distortion. It offers 100% UV Protection to spare your eyes from the sun s harmful rays. Metal detailing give these glasses extra style.</product_description><buy_url>http://www.sunandski.com/ProductDetails.asp?ProductCode=0084064919011</buy_url><large_image_url>imgs/products/lrg/0084064919011.jpg</large_image_url><remote_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919011-2T.jpg</remote_image_url><small_image_url>http://www.sunandski.com/v/vspfiles/photos/0084064919011-1.jpg</small_image_url><size/><savings>54</savings></product>
</products>
XML
);
$arr=array();
foreach($xml->product as $aTask)
{
$arr[]=$aTask;
}
//print_r($arr);
usort($arr,function($a,$b){
return sort($a->category)-strtotime($b->category);
});
//print_r($arr);
$xml=simplexml_load_string(<<<XML
<?xml version="1.0"?>
<products>
</products>
XML
);
foreach($arr as $aTask)
{
$tTask=$xml->addChild($aTask->getName());
$tTask->addChild($aTask->date->getName(),(string)$aTask->name);
$tTask->addChild($aTask->title->getName(),(string)$aTask->category);
$tTask->addChild($aTask->description->getName(),(string)$aTask->product_description);
}
echo $xml->asXML();
Fatal error: Uncaught TypeError: sort(): Argument #1 ($array) must be of type array, SimpleXMLElement given in /in/iRSbL:15
Stack trace:
#0 /in/iRSbL(15): sort(Object(SimpleXMLElement))
#1 [internal function]: {closure}(Object(SimpleXMLElement), Object(SimpleXMLElement))
#2 /in/iRSbL(14): usort(Array, Object(Closure))
#3 {main}
thrown in /in/iRSbL on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: sort(): Argument #1 ($array) must be of type array, SimpleXMLElement given in /in/iRSbL:15
Stack trace:
#0 /in/iRSbL(15): sort(Object(SimpleXMLElement))
#1 [internal function]: {closure}(Object(SimpleXMLElement), Object(SimpleXMLElement))
#2 /in/iRSbL(16): usort(Array, Object(Closure))
#3 {main}
thrown in /in/iRSbL on line 15
Process exited with code 255.
Warning: sort() expects parameter 1 to be array, object given in /in/iRSbL on line 15
Warning: sort() expects parameter 1 to be array, object given in /in/iRSbL on line 15
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 27
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 28
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 29
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 27
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 28
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 29
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 27
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 28
Warning: SimpleXMLElement::addChild(): Element name is required in /in/iRSbL on line 29
<?xml version="1.0"?>
<products>
<product/><product/><product/></products>