I just wanna add an additional to
"Append/combine/merge one simplexml to another"
The parent should has attributes too.
<?php
function append_simplexml(&$simplexml_to, &$simplexml_from)
{
static $firstLoop=true;
if( $firstLoop )
{
foreach( $simplexml_from->attributes() as $attr_key => $attr_value )
{
$simplexml_to->addAttribute($attr_key, $attr_value);
}
}
foreach ($simplexml_from->children() as $simplexml_child)
{
$simplexml_temp = $simplexml_to->addChild($simplexml_child->getName(), (string) $simplexml_child);
foreach ($simplexml_child->attributes() as $attr_key => $attr_value)
{
$simplexml_temp->addAttribute($attr_key, $attr_value);
}
$firstLoop=false;
append_simplexml($simplexml_temp, $simplexml_child);
}
unset( $firstLoop=false );
}
?>
I have aproblem to assign an object into a variable used as an object later, Then i found the code above, it solve half of my problem. I have it should have the parent name assign too but it didnt. Any better code?