Fix child name hash not to give "undefined array key" Notices

This commit is contained in:
Rowan Collins 2012-10-13 23:56:26 +01:00
parent 16d724ed78
commit 7c746c4485

View file

@ -137,7 +137,17 @@ function simplexml_dump(SimpleXMLElement $sxml, $return=false)
$child_names = array();
foreach ( $children as $sx_child )
{
$child_names[ $sx_child->getName() ]++;
// Below is a rather clunky way of saying $child_names[ $sx_child->getName() ]++;
// which avoids Notices about unset array keys
$child_node_name = $sx_child->getName();
if ( array_key_exists($child_node_name, $child_names) )
{
$child_names[$child_node_name]++;
}
else
{
$child_names[$child_node_name] = 1;
}
}
ksort($child_names);
$child_name_output = array();