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; protected $lastKey = 'item'; 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 addAttribs(array $attribs, SimpleXMLElement $node) { if (count($attribs)) { foreach ($attribs as $attrKey => $attrVal) { $node->addAttribute($attrKey, $attrVal); } } return $node; } protected function tryToAddAttribs(array &$inner, SimpleXMLElement $node) { if (isset($inner['attributes'])) { $this->addAttribs($inner['attributes'], $node); unset($inner['attributes']); } return $node; } protected function addEnum(array $items, SimpleXMLElement $node, $caption) { if (count($items)) { foreach ($items as $item) { $subNode = $node->addChild($caption); $this->tryToAddAttribs(&$inner, $subNode); } } } protected function a2x(array $inner, SimpleXMLElement $node) { $this->tryToAddAttribs(&$inner, $node); if (count($inner)) { foreach ($inner as $key => $value) { if ($this->isEnumeration($value)) { foreach ($inner as $item) { $this->addEnum($item, $node, $this->lastKey); } } else { $this->lastKey = $key; $subNode = $node->addChild($key); $this->a2x($value, $subNode); } } } return $this->res; } protected function isEnumeration(array $items) { $keys = array_keys($items); foreach ($keys as $key) { if (!is_numeric($key)) { return false; } } return true; } } $a2x = new Conv($context); var_dump($a2x->conv()); //->asXML();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.5.30.0030.03717.17
5.5.20.0070.03717.26
5.5.10.0030.03717.18
5.5.00.0070.06017.22
5.4.190.0030.03719.25
5.4.180.0030.03718.89
5.4.170.0030.06318.88
5.4.160.0070.05719.08
5.4.150.0130.05719.01
5.4.140.0030.04016.30
5.4.130.0030.03316.39
5.4.120.0000.03716.43
5.4.110.0000.04016.41
5.4.100.0070.03316.46
5.4.90.0000.03716.42
5.4.80.0000.04016.41
5.4.70.0070.03716.41
5.4.60.0100.03716.43
5.4.50.0000.03716.39
5.4.40.0070.03016.34
5.4.30.0030.03316.46
5.4.20.0000.04016.38
5.4.10.0000.04016.27
5.4.00.0070.03015.88
5.3.270.0070.04014.60
5.3.260.0100.03314.52
5.3.250.0130.03014.52
5.3.240.0000.04014.43
5.3.230.0000.04014.53
5.3.220.0000.04014.50
5.3.210.0070.03714.52
5.3.200.0000.04014.64
5.3.190.0000.04014.56
5.3.180.0100.03314.53
5.3.170.0030.03714.50
5.3.160.0030.03714.48
5.3.150.0000.04014.52
5.3.140.0000.04014.50
5.3.130.0000.04014.36
5.3.120.0030.03714.47
5.3.110.0100.03314.37
5.3.100.0100.03013.98
5.3.90.0030.05313.99
5.3.80.0030.04013.98
5.3.70.0030.04313.98
5.3.60.0000.06313.97
5.3.50.0100.06713.70
5.3.40.0030.05713.88
5.3.30.0030.05713.68
5.3.20.0000.06013.64
5.3.10.0100.05313.66
5.3.00.0070.07013.56

preferences:
139.32 ms | 1394 KiB | 7 Q