3v4l.org

run code in 300+ PHP versions simultaneously
<?php $context = [ 'mes' => [ 'attributes' => [ 't' => 'AddEvent', 'id' => 'test_id', ], 'ev' => [ 'attributes' => [ 'evt' => 'packet20130828ki3si0', 'src' => 'NVV', 'st' => 'test', 'start' => '12423511247', 'stop' => '12423991978', 'addrtype' => 'MB', 'clntID' => '+380957700418', 'lg' => '', 'bank' => '', 'lang' => '', 'prior' => '', 'brnm' => '', 'extref' => '', 'intref' => '', 'extaddrtype' => '', 'extaddrid' => '', 'recall' => '', ], 'attr' => [ [ 'attributes' => [ 'code' => '1', 'val' => '11', ], ], [ 'attributes' => [ 'code' => '2', 'val' => '12', ], ], ], 'hist' => [ [ 'attributes' => [ 'st' => '', 'ch' => '', 'lg' => '', 'con' => '', 'com' => '', 'addrtype' => '', 'addrid' => '', 'dt' => '', 'contactId' => '', ], ], ], ], ], ]; class Conv { protected $res; protected $context; public function __construct(array $context) { if (count($context) != 1) { throw new Exception('Must be only one root element', 500); } $this->context = $context; $this->init(key($this->context)); } public function conv() { return $this->a2x(current($this->context), $this->res)->asXML(); } protected function init($root) { $this->res = new SimpleXMLElement("<{$root}/>"); } protected function a2x(array $inner, SimpleXMLElement $node) { foreach ($inner as $key => $value) { if ($key == 'attributes') { if (count($value)) { foreach ($value as $attrKey => $attrVal) { var_dump($attrKey, $attrVal); $node->addAttribute($attrKey, $attrVal); } } } else { $subNode = $node->addChild($key); $this->a2x($value, $subNode); } } return $this->res; } } $a2x = new Conv($context); echo $a2x->conv()->asXML();
Output for git.master, git.master_jit, rfc.property-hooks
string(1) "t" string(8) "AddEvent" string(2) "id" string(7) "test_id" string(3) "evt" string(20) "packet20130828ki3si0" string(3) "src" string(3) "NVV" string(2) "st" string(4) "test" string(5) "start" string(11) "12423511247" string(4) "stop" string(11) "12423991978" string(8) "addrtype" string(2) "MB" string(6) "clntID" string(13) "+380957700418" string(2) "lg" string(0) "" string(4) "bank" string(0) "" string(4) "lang" string(0) "" string(5) "prior" string(0) "" string(4) "brnm" string(0) "" string(6) "extref" string(0) "" string(6) "intref" string(0) "" string(11) "extaddrtype" string(0) "" string(9) "extaddrid" string(0) "" string(6) "recall" string(0) "" string(4) "code" string(1) "1" string(3) "val" string(2) "11" string(4) "code" string(1) "2" string(3) "val" string(2) "12" string(2) "st" string(0) "" string(2) "ch" string(0) "" string(2) "lg" string(0) "" string(3) "con" string(0) "" string(3) "com" string(0) "" string(8) "addrtype" string(0) "" string(6) "addrid" string(0) "" string(2) "dt" string(0) "" string(9) "contactId" string(0) "" Fatal error: Uncaught Error: Call to a member function asXML() on string in /in/Ns4JV:105 Stack trace: #0 {main} thrown in /in/Ns4JV on line 105
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.53 ms | 402 KiB | 8 Q