3

I want to create a XML document from these arrays I have. The arrays looks like this:

Array
(
    [0] => Firstname1
    [1] => Firstname2
    [2] => Firstname3
)

Array
(
    [0] => Lastname1
    [1] => Lastname2
    [2] => Lastname3
)
...........

I want the XML document to be structured like this:

<Member>
<Firstname>Firstname1</Firstname>
<Lastname>Lastname1 </Lastname>
</Member>

How can I do that? Thanks for help!

e.e
  • 85
  • 2
  • 5
  • 4
    Have you tried anything? We're not here to do your work. – looper Nov 26 '12 at 10:02
  • pretty much a duplicate of http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml – MLeFevre Nov 26 '12 at 10:05
  • Use [SimpleXML](http://php.net/manual/en/book.simplexml.php) – Sergey Karasev Nov 26 '12 at 10:05
  • Have you tried the [SimpleXML](http://php.net/manual/en/book.simplexml.php) in PHP? – williamcarswell Nov 26 '12 at 10:06
  • [xml from array](http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml). – harry Nov 26 '12 at 10:07
  • 2
    A bit of googling would have helped you enormously ... There are tons of [tutorials](https://www.google.nl/search?q=php+create+XML&aq=f&oq=php+create+XML&aqs=chrome.0.57j60j0l3j62.2683&sugexp=chrome,mod=0&sourceid=chrome&ie=UTF-8) – Dorvalla Nov 26 '12 at 10:17

1 Answers1

3

Use this: http://php.net/manual/en/book.simplexml.php

And code (just for example how to build such structure):

$xml = new SimpleXMLElement('<xml></xml>');
foreach($first as $k=>$v){
    $member = $xml->addChild('Member');
    $member->addChild('Firstname',$v);
    $member->addChild('Lastname',$last[$k]);
}
StasGrin
  • 1,793
  • 2
  • 14
  • 30