Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array
- (
- [0] => Array
- (
- [0] => A
- [1] => B
- [2] => C
- )
- [1] => Array
- (
- [0] => 1
- [1] => 2
- [2] => 3
- )
- [2] => Array
- (
- [0] => apple
- [1] => orange
- [2] => banana
- )
- )
- public function CreateXML($array){
- foreach ($array as $arr) {
- $array2[] = $arr[0];
- }
- $xmlDoc = new DOMDocument();
- $root = $xmlDoc->appendChild(
- $xmlDoc->createElement("rootelement"));
- $tag = $root->appendChild(
- $xmlDoc->createElement("element"));
- $tag->appendChild(
- $xmlDoc->createElement("Letter", $array2[0]));
- $tag->appendChild(
- $xmlDoc->createElement("Number", $array2[1]));
- $tag->appendChild(
- $xmlDoc->createElement("Fruit", $array2[2]));
- header("Content-Type: text/plain");
- $xmlDoc->formatOutput = true;
- echo $xmlDoc->saveXML();
- }
- $newArray = array();
- for($i = 0; $i <= count($array[0]); $i++) {
- $newArray[] = array($array[0][$i], $array[1][$i], $array[2][$i]);
- }
- // Some XML here
- foreach($newArray as $row) {
- $tag->appendChild(
- $xmlDoc->createElement("Letter", $row[0]));
- $tag->appendChild(
- $xmlDoc->createElement("Number", $row[1]));
- $tag->appendChild(
- $xmlDoc->createElement("Fruit", $row[2]));
- }
- // Some more XML and output
Add Comment
Please, Sign In to add comment