PHP code example of telton / xml-to-array

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

    

telton / xml-to-array example snippets


/**
 * XML Structure:
 *
 * <tag>
 *   <announcement>This is awesome!</announcement>
 *   <author>Tyler Elton</author>
 * </tag>
 **/

$array = \Telton\XMLToArray\XMLToArray::convert($xml);

/**
 * Converted array:
 *
 * [
 *   'announcement' => 'This is awesome!',
 *   'author'       => 'Tyler Elton'
 * ]
 **/

/**
 * XML Structure:
 *
 * <tag>
 *   <announcement>This is awesome!</announcement>
 *   <author>Tyler Elton</author>
 * </tag>
 **/

$array = \Telton\XMLToArray\XMLToArray::convert($xml, true);

/**
 * Converted array:
 *
 * [
 *   'announcement' => 'This is awesome!',
 *   'author'       => 'Tyler Elton',
 *   'root'         => 'tag'
 * ]
 **/

/**
 * XML Structure:
 *
 * <tag type="announcement">
 *   <announcement>This is awesome!</announcement>
 *   <author role="developer">Tyler Elton</author>
 * </tag>
 **/

$array = \Telton\XMLToArray\XMLToArray::convert($xml, true);

/**
 * Converted array:
 *
 * [
 *   'announcement' => 'This is awesome!',
 *   'author' => [
 *      'value' => 'Tyler Elton',
 *      'role'  => 'developer'
 *    ],
 *   'root'         => 'tag',
 *   'type'         => 'announcement'
 * ]
 **/