0

As you can see below, everything go well up to uid and pwd elements. Suddenly swoops places with values. AM I missing something here?

Original code is from here.

CODE:

$array = array('table'=>'users', 'operation'=>'insert', 'uid'=>'yoyo', 'pwd'=>'123');
$output = serialize($array);

$xml = new SimpleXMLElement('<root/>');
array_walk_recursive(unserialize($output), array($xml, 'addChild'));
echo $xml->asXML();

RESULT:

<?xml version="1.0"?>
<root>
<users>table</users>
<insert>operation</insert>
<yoyo>uid</yoyo>
<123>pwd</123>
</root>
Community
  • 1
  • 1
BentCoder
  • 12,257
  • 22
  • 93
  • 165

1 Answers1

1

As per your need you have to flip your array so try,

Changing your line

$output = serialize($array); 

with

$output = serialize(array_flip($array));
Rikesh
  • 26,156
  • 14
  • 79
  • 87