protected function arrayWalk(RecursiveArrayIterator $iterator, &$result, $primaryKey)
    {
        while($iterator->valid())
        {
            if($iterator->hasChildren())
            {
                if($iterator->getChildren()->hasChildren())
                {
                    $this->arrayWalk($iterator->getChildren(), $result[$iterator->key()], null);
                }
                else
                {
                    if('' !== $primaryKey && false === is_numeric($iterator->key()) && is_string($iterator->key()))
                    {
                        $this->arrayWalk($iterator->getChildren(), $result, $iterator->key());
                    }
                    else
                    {
                        $this->arrayWalk($iterator->getChildren(), $result[$iterator->key()], $primaryKey);
                    }
                }
            }
            else
            {
                if('' !== (string) $primaryKey)
                {
                    $result[$iterator->key()] = ['@value' => $iterator->current()];
                }
                else
                {
                    $result[$primaryKey][$iterator->key()] = ['@value' => $iterator->current()];
                }
            }

            $iterator->next();
        }
    }