3v4l.org

run code in 300+ PHP versions simultaneously
<?php $context = [ 'mes' => [ 'attributes' => [ 't' => 'AddEvent', 'id' => 'test_id', 'text' => 'русский текст' ], '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 $charset; public function __construct(array $context, $charset = 'UTF-8') { if (count($context) != 1) { throw new Exception('Must be only one root element', 500); } $this->context = $context; $this->charset = $charset; $this->init(key($this->context)); } public function conv() { return $this->formatXml($this->a2x(current($this->context), $this->res)); } protected function init($root) { $header = "<?xml version=\"1.0\" encoding=\"{$this->charset}\"?><{$root}/>"; $this->res = new SimpleXMLElement($header); } 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) { $this->dump('adding enum', ['caption'=>$caption,'items'=>$items]); if (count($items)) { foreach ($items as $item) { $subNode = $node->addChild($caption); $this->tryToAddAttribs($item, $subNode); unset($item['attributes']); } } } protected function a2x(array $inner, SimpleXMLElement $node) { $this->tryToAddAttribs($inner, $node); unset($inner['attributes']); if (count($inner)) { foreach ($inner as $key => $value) { $this->dump('cur', ['key'=>$key,'val'=>$value]); if ($this->isEnumeration($value)) { $this->dump('is enum', $value); $this->addEnum($value, $node, $key); } else { $this->dump('is NOT enum', $value); $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; } protected function formatXml(SimpleXMLElement $xml) { $dom = new DOMDocument("1.0"); $dom->formatOutput = true; $dom->loadXML($xml->asXML()); return $dom->saveXML(); } protected function dump($title, $var) { if (false) { echo $title . ': ', json_encode($var) . '<hr/>'; } } } $a2x = new Conv($context); var_dump($a2x->conv());

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)
8.3.60.0100.01018.60
8.3.50.0090.01121.33
8.3.40.0120.00619.27
8.3.30.0040.01219.13
8.3.20.0000.00819.10
8.3.10.0040.00420.90
8.3.00.0100.00019.60
8.2.180.0110.01116.88
8.2.170.0080.00822.96
8.2.160.0040.01122.63
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0040.00420.10
8.2.110.0060.00322.54
8.2.100.0080.00420.01
8.2.90.0040.00418.43
8.2.80.0000.00818.13
8.2.70.0070.00718.00
8.2.60.0030.00618.30
8.2.50.0030.00618.10
8.2.40.0000.00818.53
8.2.30.0040.00419.93
8.2.20.0000.00818.13
8.2.10.0050.00318.19
8.2.00.0030.00618.11
8.1.280.0120.00325.92
8.1.270.0030.00623.99
8.1.260.0090.00626.35
8.1.250.0050.00328.09
8.1.240.0000.00924.09
8.1.230.0060.00623.00
8.1.220.0000.00817.89
8.1.210.0040.00419.09
8.1.200.0040.00417.73
8.1.190.0080.00017.60
8.1.180.0000.00818.10
8.1.170.0040.00420.64
8.1.160.0040.00419.18
8.1.150.0040.00418.93
8.1.140.0000.00817.77
8.1.130.0040.00418.20
8.1.120.0040.00417.76
8.1.110.0040.00417.83
8.1.100.0030.00517.67
8.1.90.0000.00717.82
8.1.80.0050.00317.83
8.1.70.0070.00017.63
8.1.60.0060.00317.82
8.1.50.0000.00817.70
8.1.40.0000.00917.74
8.1.30.0030.00618.02
8.1.20.0040.00418.00
8.1.10.0000.00817.92
8.1.00.0040.00417.89
8.0.300.0050.00220.47
8.0.290.0040.00417.13
8.0.280.0070.00018.76
8.0.270.0050.00317.20
8.0.260.0000.00718.96
8.0.250.0030.00517.25
8.0.240.0080.00017.21
8.0.230.0070.00017.39
8.0.220.0000.01017.29
8.0.210.0060.00317.16
8.0.200.0000.00917.30
8.0.190.0000.00817.29
8.0.180.0050.00317.18
8.0.170.0060.00317.10
8.0.160.0030.00617.18
8.0.150.0040.00417.10
8.0.140.0040.00817.25
8.0.130.0030.00313.71
8.0.120.0040.00417.13
8.0.110.0030.00617.33
8.0.100.0040.00417.21
8.0.90.0030.00517.07
8.0.80.0120.00617.34
8.0.70.0000.00817.27
8.0.60.0000.00817.33
8.0.50.0000.00817.30
8.0.30.0120.01117.29
8.0.20.0090.01117.43
8.0.10.0040.00417.27
8.0.00.0090.01317.03
7.4.330.0030.00413.43
7.4.320.0030.00316.91
7.4.300.0030.00316.72
7.4.290.0000.00716.95
7.4.280.0030.00616.68
7.4.270.0040.00416.84
7.4.260.0000.00613.66
7.4.250.0080.00016.93
7.4.240.0040.00416.86
7.4.230.0000.00716.91
7.4.220.0090.00916.92
7.4.210.0070.00916.93
7.4.200.0040.00416.98
7.4.190.0000.00717.02
7.4.160.0080.00816.78
7.4.150.0030.01617.40
7.4.140.0090.01217.38
7.4.130.0110.00916.96
7.4.120.0050.01216.86
7.4.110.0090.00916.77
7.4.100.0060.01216.60
7.4.90.0140.00316.73
7.4.80.0160.00619.03
7.4.70.0060.01216.79
7.4.60.0120.00616.71
7.4.50.0050.00317.00
7.4.40.0070.01022.27
7.4.30.0060.01216.69
7.4.00.0060.01015.28
7.3.330.0000.00513.81
7.3.320.0050.00213.68
7.3.310.0030.00316.79
7.3.300.0070.00016.78
7.3.290.0040.01116.73
7.3.280.0080.00716.74
7.3.270.0110.00717.40
7.3.260.0090.01018.24
7.3.250.0050.01216.69
7.3.240.0100.01416.78
7.3.230.0050.01216.98
7.3.210.0030.01416.86
7.3.200.0030.01419.39
7.3.190.0100.00717.00
7.3.180.0030.01316.75
7.3.170.0060.01216.76
7.3.160.0000.01716.94
7.3.120.0100.00715.01
7.2.330.0180.00016.83
7.2.320.0140.00317.22
7.2.310.0100.01017.02
7.2.300.0160.00317.04
7.2.290.0090.00817.18
7.1.70.0040.00417.34
7.1.60.0100.01019.40
7.1.50.0040.01817.08
7.1.00.0000.04322.42
7.0.200.0160.00316.59
7.0.140.0130.08722.27
7.0.90.0100.07721.79
7.0.80.0070.04321.79
7.0.70.0030.07321.77
7.0.60.0130.05721.79
7.0.50.0200.08320.50
7.0.40.0000.05020.29
7.0.30.0070.08320.17
7.0.20.0100.05020.06
7.0.10.0100.07020.16
7.0.00.0130.07720.16
5.6.280.0030.07021.06
5.6.240.0030.09020.58
5.6.230.0070.03320.81
5.6.220.0070.08020.86
5.6.210.0030.07720.71
5.6.200.0000.05021.18
5.6.190.0070.04021.25
5.6.180.0030.04721.38
5.6.170.0030.05321.08
5.6.160.0070.05721.22
5.6.150.0100.07321.30
5.6.140.0030.04021.16
5.6.130.0030.09321.22
5.6.120.0000.06721.10
5.6.110.0030.06021.27
5.6.100.0100.04321.36
5.6.90.0070.04021.20
5.6.80.0130.05020.54
5.6.70.0030.05720.59
5.6.60.0030.04720.59
5.6.50.0030.05020.58
5.6.40.0000.07720.70
5.6.30.0170.07020.69
5.6.20.0070.08720.61
5.6.10.0070.05320.46
5.6.00.0130.04320.54
5.5.380.0130.04320.50
5.5.370.0030.08020.63
5.5.360.0070.07020.62
5.5.350.0070.07720.60
5.5.340.0030.07021.07
5.5.330.0000.04721.14
5.5.320.0070.06321.13
5.5.310.0030.07721.04
5.5.300.0000.04321.04
5.5.290.0130.03721.05
5.5.280.0070.07021.14
5.5.270.0030.04721.05
5.5.260.0030.09020.91
5.5.250.0070.08720.94
5.5.240.0130.07320.41
5.5.230.0070.03720.47
5.5.220.0000.04320.48
5.5.210.0070.04320.32
5.5.200.0130.06720.30
5.5.190.0070.08320.42
5.5.180.0030.09020.25
5.5.160.0070.04320.32
5.5.150.0200.06720.31
5.5.140.0070.07720.44
5.5.130.0200.06320.22
5.5.120.0030.05320.44
5.5.110.0200.03320.37
5.5.100.0030.05320.28
5.5.90.0000.05020.36
5.5.80.0100.07720.32
5.5.70.0100.07720.32
5.5.60.0100.07320.20
5.5.50.0070.04020.29
5.5.40.0100.07020.16
5.5.30.0070.07720.20
5.5.20.0100.05320.19
5.5.10.0070.06320.09
5.5.00.0070.08020.28
5.4.450.0070.04019.49
5.4.440.0100.04719.61
5.4.430.0130.07719.58
5.4.420.0070.07719.36
5.4.410.0030.07319.48
5.4.400.0070.05319.39
5.4.390.0100.04019.20
5.4.380.0070.03319.05
5.4.370.0000.05319.27
5.4.360.0000.05019.19
5.4.350.0030.07319.26
5.4.340.0030.07319.29
5.4.320.0030.05019.27
5.4.310.0070.06719.30
5.4.300.0030.04719.29
5.4.290.0100.07019.26
5.4.280.0000.08719.25
5.4.270.0100.05719.24
5.4.260.0030.07719.27
5.4.250.0130.06018.97
5.4.240.0100.08019.38
5.4.230.0100.05319.27
5.4.220.0030.06719.25
5.4.210.0000.07719.13
5.4.200.0070.05719.25
5.4.190.0070.04719.11
5.4.180.0030.07319.29
5.4.170.0100.07319.14
5.4.160.0230.05319.11
5.4.150.0100.05319.23
5.4.140.0170.04716.44
5.4.130.0000.05016.51
5.4.120.0030.04716.60
5.4.110.0100.04316.55
5.4.100.0130.03316.51
5.4.90.0070.03316.70
5.4.80.0030.04016.53
5.4.70.0070.03716.50
5.4.60.0070.04016.76
5.4.50.0100.06716.59
5.4.40.0170.06016.66
5.4.30.0070.04016.67
5.4.20.0030.04016.48
5.4.10.0000.05316.59
5.4.00.0000.03716.01
5.3.290.0070.04314.66
5.3.280.0100.05714.58
5.3.270.0070.05314.61
5.3.260.0070.04714.45
5.3.250.0230.04314.60
5.3.240.0100.06714.60
5.3.230.0030.06714.61
5.3.220.0200.04714.48
5.3.210.0100.07014.55
5.3.200.0030.03714.57
5.3.190.0070.05314.56
5.3.180.0000.04314.54
5.3.170.0070.06314.43
5.3.160.0030.04014.39
5.3.150.0030.07714.45
5.3.140.0100.03314.55
5.3.130.0030.05014.51
5.3.120.0100.03314.41
5.3.110.0100.04314.55
5.3.100.0030.03013.95
5.3.90.0070.07713.96
5.3.80.0130.07013.77
5.3.70.0070.05713.96
5.3.60.0030.04313.88
5.3.50.0030.06313.93
5.3.40.0000.04313.94
5.3.30.0030.03713.89
5.3.20.0030.03313.55
5.3.10.0000.03713.52
5.3.00.0070.03313.62
5.2.170.0000.03311.13
5.2.160.0000.02711.20
5.2.150.0030.03011.14
5.2.140.0000.03011.21
5.2.130.0030.02711.05
5.2.120.0030.02710.93
5.2.110.0000.03011.02
5.2.100.0030.03011.06
5.2.90.0030.02311.05
5.2.80.0000.03011.12
5.2.70.0030.02311.09
5.2.60.0000.03010.87
5.2.50.0030.03010.86
5.2.40.0070.02311.07
5.2.30.0000.03310.97
5.2.20.0000.03010.85
5.2.10.0030.02710.90
5.2.00.0100.02010.64
5.1.60.0030.02310.04
5.1.50.0000.0279.98
5.1.40.0000.02710.01
5.1.30.0030.02310.39
5.1.20.0070.02010.25
5.1.10.0030.02310.11
5.1.00.0000.02710.10
5.0.50.0000.0208.56
5.0.40.0000.0178.46
5.0.30.0000.0308.21
5.0.20.0030.0308.29
5.0.10.0100.0138.23
5.0.00.0030.0338.25
4.4.90.0000.0176.95
4.4.80.0000.0176.95
4.4.70.0000.0176.95
4.4.60.0000.0176.95
4.4.50.0030.0136.95
4.4.40.0030.0206.95
4.4.30.0000.0176.95
4.4.20.0000.0206.95
4.4.10.0000.0176.95
4.4.00.0030.0206.95
4.3.110.0030.0106.95
4.3.100.0000.0206.95
4.3.90.0070.0106.95
4.3.80.0000.0276.95
4.3.70.0000.0176.95
4.3.60.0000.0206.95
4.3.50.0030.0136.95
4.3.40.0000.0476.95
4.3.30.0030.0136.95
4.3.20.0000.0176.95
4.3.10.0000.0136.95
4.3.00.0000.0136.95

preferences:
56.16 ms | 401 KiB | 5 Q