PHP code example of alyjee / from-xml-to-array

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

    

alyjee / from-xml-to-array example snippets


use Alyjee\XmlToArray\XmlToArray;

$xml = '<items><Facilities><Facility Code="*EC"><![CDATA[Earliest check-in at 14:00]]></Facility><Facility Code="*LF"><![CDATA[1 lift]]></Facility><Facility Code="*RS"><![CDATA[Room Service from 18:00 to 21:00]]></Facility></Facilities></items>';

$result = XmlToArray::convert($xml);

Array
(
    [items] => Array
        (
            [Facilities] => Array
                (
                    [Facility] => Array
                        (
                            [0] => Array
                                (
                                    [_attributes] => Array
                                        (
                                            [Code] => *EC
                                        )

                                    [_cdata] => Earliest check-in at 14:00
                                )

                            [1] => Array
                                (
                                    [_attributes] => Array
                                        (
                                            [Code] => *LF
                                        )

                                    [_cdata] => 1 lift
                                )

                            [2] => Array
                                (
                                    [_attributes] => Array
                                        (
                                            [Code] => *RS
                                        )

                                    [_cdata] => Room Service from 18:00 to 21:00
                                )

                        )

                )

        )

)