I am in need of help to figure out something.
On my last question I was talking about parsing a XML and listing the values on html: Parse XML to HTML with PHP SimpleXMLElement
I got that going really well, but then a new variable presented itself. :)
This is my XML:
<?xml version='1.0'?>
<AdXML>
<Response>
<Campaign>
<Overview>
<Name>strip</Name>
<Description>category</Description>
<Status>L</Status>
</Overview>
<Pages>
<Url>page01</Url>
<Url>page02</Url>
<Url>page03</Url>
</Pages>
</Campaign>
</Response>
</AdXML>
My problem start when my XML generate the page's list random.so, one time it would load like this and another time it will load like this:
<?xml version='1.0'?>
<AdXML>
<Response>
<Campaign>
<Overview>
<Name>strip</Name>
<Description>category</Description>
<Status>L</Status>
</Overview>
<Pages>
<Url>page02</Url>
<Url>page03</Url>
<Url>page01</Url>
</Pages>
</Campaign>
</Response>
</AdXML>
So I went from a simple:
<?php foreach ($xmlparsed->Response->Campaign->Pages->Url as $Url) {echo $Url, '<br>';} ?>
to:
<?php
$urlarray = array();
foreach ($xmlparsed->Response->Campaign->Pages->Url as $Url) {$urlarray[] = $Url;}
sort($urlarray);
foreach ($urlarray as $key => $val){echo $key,'|',$val, '<br>';}
?>
What I am trying to do is to create an array with the information and then sort the pages alphabetically. I do not understand why cant I sort by value (pages), I can only sort by key and that defeat the purpose just because the xml is generated dynamically and I have no control on how it is formed.
ay help would be greatly appreciated .
cheers