PHP code example of timkippdev / array-to-xml-converter

1. Go to this page and download the library: Download timkippdev/array-to-xml-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

timkippdev / array-to-xml-converter example snippets


use TimKippDev\ArrayToXmlConverter\ArrayToXmlConverter;

...

$data = [
    'product-1' => [
        '_attributes' => [
            'key' => 'value'
        ], 
        'title' => 'Product One',
        'price' => [
            '_attributes' => [
                'locale' => 'us'
            ],
            '_value' => '$9.99'
        ]
    ],
    'product-2' => [
        'title' => 'Product Two',
        'price' => '$12.99'
    ]
];

$xml = ArrayToXmlConverter::convert($data);

use TimKippDev\ArrayToXmlConverter\ArrayToXmlConverter;

... 

$data = [
    'foo' => 'bar'
];

$xml = ArrayToXmlConverter::convert($data, [
    'encoding' => 'ISO-8859-15', // default - "UTF-8"
    'formatOutput' => true, // default - true
    'rootName' => 'new-root', // default - "root"
    'rootAttributes' => [
        'key' => 'value'
    ], // default - no attributes (empty array)
    'version' => '2.0' // default - "1.0"
]);
bash
php vendor/bin/phpunit