tricks of it demos

How to Convert XML into Associative Array in PHP

XML
<?xml version='1.0'?> 
<books>  
    <book name='Java'>  
        <reference>book1</reference>  
    </book>  
    <book name='PHP'>  
        <reference>book2</reference>  
    </book>
	<book name='Android'>  
        <reference>book3</reference>  
    </book>
	<book name='Web'>  
        <reference>book4</reference>  
    </book>
</books>
XML Objects
SimpleXMLElement Object
(
    [book] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [name] => Java
                        )

                    [reference] => book1
                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [name] => PHP
                        )

                    [reference] => book2
                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [name] => Android
                        )

                    [reference] => book3
                )

            [3] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [name] => Web
                        )

                    [reference] => book4
                )

        )

)
XML JSON

{"book":[{"@attributes":{"name":"Java"},"reference":"book1"},{"@attributes":{"name":"PHP"},"reference":"book2"},{"@attributes":{"name":"Android"},"reference":"book3"},{"@attributes":{"name":"Web"},"reference":"book4"}]}

Books Array
Array
(
    [book] => Array
        (
            [0] => Array
                (
                    [@attributes] => Array
                        (
                            [name] => Java
                        )

                    [reference] => book1
                )

            [1] => Array
                (
                    [@attributes] => Array
                        (
                            [name] => PHP
                        )

                    [reference] => book2
                )

            [2] => Array
                (
                    [@attributes] => Array
                        (
                            [name] => Android
                        )

                    [reference] => book3
                )

            [3] => Array
                (
                    [@attributes] => Array
                        (
                            [name] => Web
                        )

                    [reference] => book4
                )

        )

)