Convert XML Object to Array

Versions used: 

Below is a very quick way of converting XML to an Array:

<?php
/**
 * Convert XML to an Array.
 *
 * @param $xml_object
 *   An XML object to be converted.

 * @return
 *   returns an array representation of the XML object.
 */
function xml2array($xml_object, $data = array()) {
 
// use recursion to traverse xml object and populate array
 
foreach ((array) $xml_object as $index => $node) {
   
$data[$index] = (is_object($node)) ? xml2array($node) : $node;
  }
 
  return
$data;
}
?>