protected function convertXmlObjectToArray($xml)
    {
        $array = (array) $xml;

        if (count($array) == 0 && ! is_array($xml)) {

            $array = [ (string) $xml ];
        }

        if (is_array($array)) {

            foreach ($array as $key => $value) {

                if (is_object($value)) {

                    if (strpos(get_class($value), "SimpleXML") !== false) {

                        $array[ $key ] = $this->convertXmlObjectToArray($value);

                    } else {

                        $array[ $key ] = $this->convertXmlObjectToArray( (array) $value );
                    }

                } elseif (is_array($value)) {

                    $array[ $key ] = $this->convertXmlObjectToArray($value);
                }
            }
        }

        return $array;
    }
protected function convertXmlObjectToArray($xml)
    {
        $array = (array) $xml;

        if (count($array) == 0 && ! is_array($xml)) {

            $array = [ (string) $xml ];
        }

        if (is_array($array)) {

            foreach ($array as $key => $value) {

                if (is_object($value)) {

                    if (strpos(get_class($value), "SimpleXML") !== false) {

                        $array[ $key ] = $this->convertXmlObjectToArray($value);

                    } else {

                        $array[ $key ] = $this->convertXmlObjectToArray( (array) $value );
                    }

                } elseif (is_array($value)) {

                    $array[ $key ] = $this->convertXmlObjectToArray($value);
                }
            }
        }

        return $array;
    }
protected function convertXmlObjectToArray ( $ xml ) { $ array = ( array ) $ xml ; if ( count ( $ array ) == 0 && ! is_array ( $ xml ) ) { $ array = [ ( string ) $ xml ] ; } if ( is_array ( $ array ) ) { foreach ( $ array as $ key => $ value ) { if ( is_object ( $ value ) ) { if ( strpos ( get_class ( $ value ) , "SimpleXML" ) !== false ) { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( $ value ) ; } else { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( ( array ) $ value ) ; } } elseif ( is_array ( $ value ) ) { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( $ value ) ; } } } return $ array ; }
Converts SimpleXml structure to array

@param SimpleXmlElement|array|object $xml
@return array
Converts SimpleXml structure to array