PHP code example of giunashvili / xml-parser

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

    

giunashvili / xml-parser example snippets


use Giunashvili\XMLParser\Parse;

$arr = [ 
    'animals' => [
        'bear'      => 'black',
        'fox'       => 'red',
        'Kangaroo'  => 'Jack'
    ],
    'plants' => [
        'bamboo',
        'apple'
    ]
];


$xmlWithoutDefinedWrapper = Parse :: arrayAsXml( $arr );

echo $xmlWithoutDefinedWrapper;
/**
    <data>
        <animals>
            <bear>      black   </bear>
            <fox>       red     </fox>
            <Kangaroo>  Jack    </Kangaroo>
        </animals>
        <plants>
            <item-0>    bamboo  </item-0>
            <item-1>    bamboo  </item-1>
        </plangs>
    </data>
*/


$xmlWithDefinedWrapper    = Parse :: arrayAsXml( $arr, 'classifications' );

echo $xmlWithoutDefinedWrapper;
/**
    <classifications>
        <animals>
            <bear>      black   </bear>
            <fox>       red     </fox>
            <Kangaroo>  Jack    </Kangaroo>
        </animals>
        <plants>
            <item-0>    bamboo  </item-0>
            <item-1>    bamboo  </item-1>
        </plangs>
    </classifications>
*/