Error converting array to xml

0

I have the following array:

Array
(
 [mode] => default
 [method] => boleto
 [sender] => Array(
        [name] => Fulano Silva
        [email] => [email protected]
        [phone] => Array
            (
                [areaCode] => 11
                [number] => 30380000
            )

        [documents] => Array
            (
                [document] => Array
                    (
                        [type] => CPF
                        [value] => 11475714734
                    )

            )

        [hash] => abc1234
    )

 [currency] => BRL
 [notificationURL] => https://sualoja.com.br/notificacao
 [items] => Array
    (
        [id] => 1
        [description] => Descricao do item a ser vendido
        [quantity] => 2
        [amount] => 1.00
    )

 [extraAmount] => 1
 [reference] => R123456
 [shipping] => Array
    (
        [address] => Array
            (
                [street] => Av. Brigadeiro Faria Lima
                [number] => 1384
                [complement] => 1 andar
                [district] => Jardim Paulistano0
                [city] => Sao Paulo
                [state] => SP
                [country] => BRA
                [postalCode] => 01452002
            )

        [type] => 3
        [cost] => 0.00
    )

)

And I use the following method in a class:

public function convertArrayXml() {

    $xml = new SimpleXMLElement('<payment/>');

    foreach($this->payment as $chave => $item)
    {
        if(is_array($item))
        {
            $subNo = $xml->addChild($chave);
            array_to_xml($item, $subNo);
        } else {
            $xml->addChild($chave,$item);
        }
    }
    return $xml->asXML();
}

This method has the function to convert the array to an xml, however it is presenting me with an error:

127.0.0.1:47784 [500]: / - 
Uncaught Error: Call to undefined function array_to_xml() 
in /var/www/html/sandbox/pagseguroTransparente/pagSeguroTransparenteBoleto.php:109
Stack trace:
#0 /var/www/html/sandbox/pagseguroTransparente/index.php(41): 
pagSeguroTransparenteBoleto->convertArrayXml()
#1 {main}
  thrown in /var/www/html/sandbox/pagseguroTransparente/pagSeguroTransparenteBoleto.php
   on line 109

Someone who has been through this can tell me how to solve the problem?

    
asked by anonymous 23.09.2018 / 21:00

0 answers