Узлы сортировки и обновления PHP

Я боролся с этим весь день 🙁

Хотя я нашел ответы на подобные вопросы, они не обновляют существующий XML, они создают новый XML.

Любая помощь будет очень высоко ценится.

Это XML, который я загружаю и пытаюсь отсортировать только узлы images-> image:

<?xml version="1.0"?> <stuff> <other_nodes> </other_nodes> <images> <image><sorted_number><![CDATA[1]]></sorted_number></image> <image><sorted_number><![CDATA[3]]></sorted_number></image> <image><sorted_number><![CDATA[2]]></sorted_number></image> </images> </stuff> //load the xml into a var $theXML = //load the xml from the database $imageNode = $theXML->images; //sort the images into sorted order $d = $imageNode; // turn into array $e = array(); foreach ($d->image as $image) { $e[] = $image; } // sort the array usort($e, function($a, $b) { return $a->sorted_number - $b->sorted_number; }); //now update the xml in the correct order foreach ($e as $node) { //???unsure how to update the images node in my XML } 

Solutions Collecting From Web of "Узлы сортировки и обновления PHP"