Simply put, creating an XML string with array_walk_recursive()
appears to place the keys as values and values as keys. What am I doing wrong?
$root = 'Auth';
$auth['user'] = 'JohnSmith';
$auth['password'] = 'somePassword';
$xml = new SimpleXMLElement("<${root}/>");
array_walk_recursive($auth, [$xml, 'addChild']);
echo $xml->asXml();
/**
* <?xml version="1.0"?>
* <Auth>
* <JohnSmith>user</JohnSmith>
* <somePassword>password</somePassword>
* </Auth>
*/
There are a number of resources on SO and Google that have this explicit setup as "how it's done" and none of them seem to notice the reversal even though it's there in their dumped output