reordering array attributes then save back to XML in php

前端 未结 2 1554
春和景丽
春和景丽 2021-01-24 07:57

I have this XML:

  
    B
  
  
    C
  <         


        
相关标签:
2条回答
  • 2021-01-24 08:14

    In XML order of nodes in same level is doesn't matter then you can't do this by theory, by practice user other library.

    0 讨论(0)
  • 2021-01-24 08:25

    Numerical id order is maintained and made consecutive:

    $objXML = new SimpleXMLElement(XML_FILE_NAME, null, true);
    $picture = $objXML->xpath('picture');
    usort($picture, create_function('$a,$b', 'return (string)$a["id"] - (string)$b["id"];'));
    foreach ($pictures as $index => $node) $node["id"] = $index;
    
    0 讨论(0)
提交回复
热议问题