I have this XML:
<picture id="2">
<title>B</title>
</picture>
<picture id="3">
<title>C</title>
</picture>
<picture id="0">
<title>A</title>
</picture>
Trying to achieve this:
<picture id="1">
<title>B</title>
</picture>
<picture id="2">
<title>C</title>
</picture>
<picture id="0">
<title>A</title>
</picture>
Using this to get a list of ‘id’ attribute values:
$objXML = new SimpleXMLElement(XML_FILE_NAME, null, true);
$picture = $objXML->xpath('picture');
$arrayCurrent = array();
foreach($picture as $value) {
$arrayCurrent[] = (string)$value['id'];
}
sort($arrayCurrent); // put XML into numerical 'id' order
print_r($arrayCurrent);
It returns: Array ( [0] => 0 [1] => 2 [2] => 3 ) Any ideas how to re-index like so: 0, 1, 2 and save the appropriate ‘id’ attributes back to their correct positions in the XML doc?
Thanks, Andy