PHP code example of fillup / array2xml

1. Go to this page and download the library: Download fillup/array2xml 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/ */

    

fillup / array2xml example snippets


[
    'contact' => [
        'type' => 'email',
        'value' => '[email protected]',
    ]
]

[
    '/path/to/contact' => [
        'attributes' => [
            'type'
        ]
    ]
]


use fillup\A2X;

$data = [
    'person' => [
        'name' => 'Daddio',
        'children' => [
            [
                'name' => 'Older Brother',
            ],
            [
                'name' => 'Little Sister',
            [
        ]
    ]
];

$schema = [
    '/person/children' => [
        'sendItemsAs' => 'child',
        '


use fillup\A2X;

$data = [
    'person' => [
        'attributeName' => 'attribute value',
        'name' => [
            'given' => 'first',
            'surname' => 'last',
        ],
        'address' => [
            'street1' => '123 Somewhere',
            'street2' => '',
            'city' => 'Anytown',
            'state' => 'AA',
            'country' => 'USA',
        ],
        'age' => 40,
        'contacts' => [
            [
                'type' => 'email',
                'value' => '[email protected]',
            ],
            [
                'type' => 'mobile',
                'value' => '11235551234',
            ],
        ],
    ],
];

$schema = [
    '/person' => [
        'attributes' => [
            'attributeName',
        ],
    ],
    '/person/contacts' => [
        'sendItemsAs' => 'contact',
        'namespace' => 'ns1',
        'childNamespace' => 'ns2',
    ],
    '/person/contacts/contact' => [
        'attributes' => [
            'type',
        ],
    ],
    '@namespaces' => [
        'ns1' => 'http://namespaceone.com',
        'ns2' => 'http://namespacetwo.com',
    ],
];

$a2x = new A2X($data, $schema);
$xml = $a2x->asXml();