i've managed to parse an array out of my own language. (for this: called lance project language - lpl)
so.. \lance(says(hello)) will be formatted to
Array
(
[0] => lpl_struct
(
[args] => Array
(
[0] => Array
(
[0] => lpl_struct
(
[args] => Array
(
[0] => Array
(
[0] => lpl_struct
(
[args] => Array
(
[0] => hello
)
[funcname] => text
)
)
)
[funcname] => says
)
)
)
[funcname] => lance
)
)
im now trying to create an xml struct out of this, here is my attempt to do so:
function arr2xml($array) {
$xml = '';
if (is_array($array) || is_object($array)) {
foreach ($array as $key => $value) {
if (is_numeric($key)) {
#move deeper in array to get the right NON-NUMERIC key
}
$xml .= '<' . $key . '>' . "\n" . $this->arr2xml($value) . '</' . $key . '>' . "\n";
}
} else {
$xml = htmlspecialchars($array, ENT_QUOTES) . "\n";
}
return $xml;
}
what i'm getting out of it so far is:
<0>
<args>
<0>
<0>
<args>
<0>
<0>
<args>
<0>
hello
</0>
</args>
<funcname>
text
</funcname>
</0>
</0>
</args>
<funcname>
says
</funcname>
</0>
</0>
</args>
<funcname>
lance
</funcname>
</0>
is it possible to "skip" the numeric keys in the array?. say to.. move deeper to the next "real" array key?
our should i rethink my created array
thanks for any answer.
sry for bad formatting. im kinda new to stackoverflow. lance
I tried to rebuild your array using the following:
I then updated your arr2xml function:
This produced the following, which is close to what you're looking for:
The only thing missing is the root element. You can add that manually using:
Hope this helps!