Skip to content

Commit

Permalink
Parent key for singular data
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Jun 3, 2019
1 parent 00e2725 commit ffc33f2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Traits/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

trait Parser
{
function arrayToXml( SimpleXMLElement $object, array $data )
function arrayToXml( SimpleXMLElement $object, array $data, $parent_key = null )
{
foreach ( $data as $key => $value ) {
if ( is_numeric( $key ) ) {
$key = str_singular( $key );
if ( is_numeric( $key ) && !is_null( $parent_key ) ) {
$key = str_singular( $parent_key );
}
if ( is_array( $value ) ) {
$new_object = $object->addChild( $key );
$this->arrayToXml( $new_object, $value );
$this->arrayToXml( $new_object, $value, $key );
} else {
$object->addChild( $key, $value );
}
Expand Down

0 comments on commit ffc33f2

Please sign in to comment.