I am trying to convert an xml document into an associative array.
I want the name of the array to be the root node in the xml document.
I get this information by $xml->getName() .
I thought of creating an empty array using this statement, but it does not work.
$($xml->getName()) = array();
Other way should be creating a temp variable and renaming it with $xml->getName(). Is there a way I can do this in PHP?
You can create it this way:
You may also wish to validate the name to ensure it meets PHP variable name standards to avoid a runtime error.