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; 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) { $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 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.0030.01318.81
8.3.50.0130.00822.13
8.3.40.0100.01319.17
8.3.30.0190.00319.52
8.3.20.0050.00320.57
8.3.10.0030.00522.13
8.3.00.0000.00821.00
8.2.180.0110.01118.79
8.2.170.0040.01122.96
8.2.160.0140.00522.44
8.2.150.0000.00824.18
8.2.140.0030.00624.66
8.2.130.0070.00026.16
8.2.120.0040.00421.32
8.2.110.0090.00021.20
8.2.100.0000.01218.22
8.2.90.0040.00419.47
8.2.80.0040.00418.30
8.2.70.0110.00017.75
8.2.60.0050.00318.18
8.2.50.0040.00418.07
8.2.40.0090.00318.47
8.2.30.0040.00418.41
8.2.20.0040.00418.16
8.2.10.0000.00818.06
8.2.00.0060.00318.10
8.1.280.0000.01925.92
8.1.270.0030.00624.22
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00624.09
8.1.230.0060.00621.27
8.1.220.0040.00418.04
8.1.210.0080.00018.77
8.1.200.0030.00617.85
8.1.190.0040.00418.02
8.1.180.0060.00318.10
8.1.170.0030.00619.08
8.1.160.0040.00422.38
8.1.150.0000.00818.88
8.1.140.0000.00817.69
8.1.130.0000.00818.14
8.1.120.0040.00417.70
8.1.110.0050.00217.82
8.1.100.0050.00317.79
8.1.90.0040.00417.66
8.1.80.0040.00417.85
8.1.70.0000.00717.67
8.1.60.0090.00017.93
8.1.50.0090.00017.88
8.1.40.0000.00817.88
8.1.30.0040.00417.80
8.1.20.0090.00017.87
8.1.10.0000.00917.85
8.1.00.0090.00017.88
8.0.300.0000.00820.44
8.0.290.0000.00717.55
8.0.280.0030.00318.76
8.0.270.0030.00317.62
8.0.260.0000.00717.16
8.0.250.0040.00417.32
8.0.240.0050.00317.39
8.0.230.0070.00017.43
8.0.220.0040.00417.30
8.0.210.0000.00717.32
8.0.200.0000.00817.20
8.0.190.0000.00717.38
8.0.180.0000.00817.17
8.0.170.0000.00917.30
8.0.160.0000.00817.35
8.0.150.0000.00817.22
8.0.140.0000.00817.30
8.0.130.0030.00313.64
8.0.120.0000.01017.25
8.0.110.0040.00417.29
8.0.100.0070.00017.21
8.0.90.0000.00817.20
8.0.80.0060.01017.25
8.0.70.0000.00717.38
8.0.60.0040.00417.29
8.0.50.0000.00817.27
8.0.30.0100.01017.55
8.0.20.0100.00917.42
8.0.10.0000.00817.39
8.0.00.0140.00617.04
7.4.330.0030.00315.38
7.4.320.0000.00616.91
7.4.300.0000.00616.88
7.4.290.0000.00816.91
7.4.280.0040.00416.85
7.4.270.0000.00716.91
7.4.260.0000.00916.88
7.4.250.0050.00316.84
7.4.240.0050.00216.83
7.4.230.0040.00417.02
7.4.220.0070.01116.93
7.4.210.0110.00716.93
7.4.200.0000.00716.93
7.4.190.0040.00417.05
7.4.160.0070.01016.85
7.4.150.0080.00817.40
7.4.140.0070.01217.86
7.4.130.0060.01116.89
7.4.120.0060.01116.94
7.4.110.0090.00916.87
7.4.100.0100.00716.74
7.4.90.0030.01516.84
7.4.80.0060.01216.91
7.4.70.0120.00416.96
7.4.60.0150.00316.81
7.4.50.0030.00516.91
7.4.40.0100.00622.77
7.4.30.0110.00716.77
7.4.00.0100.00715.35
7.3.330.0030.00313.72
7.3.320.0050.00013.52
7.3.310.0030.00316.76
7.3.300.0070.00016.72
7.3.290.0110.00416.79
7.3.280.0090.00816.71
7.3.270.0100.00717.40
7.3.260.0090.01016.89
7.3.250.0080.01116.75
7.3.240.0100.00716.89
7.3.230.0030.01316.71
7.3.210.0090.00917.00
7.3.200.0140.00419.39
7.3.190.0030.01516.62
7.3.180.0130.00316.98
7.3.170.0070.01016.80
7.3.160.0060.01016.80
7.3.120.0040.01114.93
7.2.330.0070.01017.07
7.2.320.0130.01017.21
7.2.310.0080.01116.99
7.2.300.0140.00917.07
7.2.290.0080.00817.14
7.2.00.0260.01619.43
7.1.100.0000.01218.13
7.1.70.0040.00417.12
7.1.60.0030.02219.32
7.1.50.0100.01317.22
7.1.00.0000.08022.52
7.0.200.0080.00817.07
7.0.140.0030.07022.16
7.0.90.0200.04720.26
7.0.80.0030.05720.02
7.0.70.0530.08020.19
7.0.60.0470.06720.21
7.0.50.0530.06720.45
7.0.40.0070.08320.20
7.0.30.0100.08320.28
7.0.20.0000.05720.24
7.0.10.0070.07720.14
7.0.00.0000.09020.03
5.6.240.0130.02720.75
5.6.230.0000.04020.71
5.6.220.0070.09020.95
5.6.210.0170.06020.91
5.6.200.0070.08721.18
5.6.190.0070.05321.30
5.6.180.0070.06021.26
5.6.170.0130.07721.33
5.6.160.0200.07321.20
5.6.150.0130.08021.18
5.6.140.0070.04721.30
5.6.130.0100.08021.06
5.6.120.0130.07721.09
5.6.110.0070.07321.13
5.6.100.0130.07721.10
5.6.90.0100.07021.01
5.6.80.0100.07720.64
5.6.70.0170.07020.51
5.6.60.0070.08020.51
5.6.50.0130.07020.57
5.6.40.0170.06020.39
5.6.30.0030.06020.53
5.6.20.0030.08320.38
5.6.10.0070.08720.54
5.6.00.0070.07720.51
5.5.380.0070.05320.66
5.5.370.0070.03720.46
5.5.360.0130.08020.76
5.5.350.0070.08720.57
5.5.340.0100.05721.01
5.5.330.0100.08020.90
5.5.320.0130.07721.02
5.5.310.0070.08020.88
5.5.300.0070.07720.98
5.5.290.0100.08321.07
5.5.280.0070.04020.97
5.5.270.0030.08320.91
5.5.260.0070.08320.89
5.5.250.0070.08720.74
5.5.240.0030.07720.34
5.5.230.0130.07320.39
5.5.220.0100.05020.43
5.5.210.0130.07320.29
5.5.200.0070.07020.21
5.5.190.0030.08320.27
5.5.180.0170.07320.33
5.5.160.0200.06320.40
5.5.150.0100.08020.27
5.5.140.0030.08020.22
5.5.130.0130.07020.42
5.5.120.0030.08720.17
5.5.110.0200.06320.44
5.5.100.0030.04720.16
5.5.90.0000.05320.27
5.5.80.0200.07020.19
5.5.70.0100.05020.25
5.5.60.0100.07320.24
5.5.50.0130.07020.26
5.5.40.0070.07320.24
5.5.30.0100.04720.17
5.5.20.0130.03320.31
5.5.10.0100.07320.13
5.5.00.0000.05320.29
5.4.450.0030.08019.59
5.4.440.0070.08319.63
5.4.430.0100.04319.59
5.4.420.0030.08019.56
5.4.410.0030.08019.46
5.4.400.0030.06318.93
5.4.390.0130.06719.23
5.4.380.0100.07319.11
5.4.370.0030.04719.30
5.4.360.0030.08019.29
5.4.350.0100.07719.12
5.4.340.0100.05719.29
5.4.320.0130.06719.11
5.4.310.0070.06019.27
5.4.300.0130.07019.27
5.4.290.0130.06019.10
5.4.280.0130.06319.18
5.4.270.0100.06719.02
5.4.260.0070.05319.28
5.4.250.0030.08019.26
5.4.240.0100.07318.92
5.4.230.0030.08319.27
5.4.220.0070.08018.95
5.4.210.0030.06319.22
5.4.200.0070.07719.00
5.4.190.0030.05319.19
5.4.180.0200.05719.23
5.4.170.0070.05319.02
5.4.160.0030.08019.28
5.4.150.0070.06318.95
5.4.140.0130.05016.54
5.4.130.0070.07016.54
5.4.120.0100.07016.61
5.4.110.0170.04716.61
5.4.100.0070.04316.61
5.4.90.0100.06716.52
5.4.80.0000.05016.48
5.4.70.0200.05316.52
5.4.60.0170.04016.62
5.4.50.0070.07316.48
5.4.40.0100.03716.50
5.4.30.0070.07716.54
5.4.20.0100.06316.57
5.4.10.0130.07016.56
5.4.00.0070.06315.95
5.3.290.0130.07714.50
5.3.280.0070.05714.45
5.3.270.0070.08314.46
5.3.260.0100.07314.55
5.3.250.0070.07714.57
5.3.240.0030.07314.45
5.3.230.0100.04314.58
5.3.220.0070.08014.55
5.3.210.0130.05314.55
5.3.200.0070.07014.39
5.3.190.0100.07014.43
5.3.180.0070.04714.55
5.3.170.0030.08314.49
5.3.160.0030.07714.52
5.3.150.0130.07014.55
5.3.140.0030.08314.53
5.3.130.0000.08714.54
5.3.120.0070.07714.54
5.3.110.0100.07314.37
5.3.100.0100.07713.99
5.3.90.0030.08314.01
5.3.80.0100.06313.77
5.3.70.0000.05013.98
5.3.60.0030.06313.99
5.3.50.0100.06713.93
5.3.40.0030.06713.89
5.3.30.0000.08013.85
5.3.20.0100.07013.65
5.3.10.0070.04313.60
5.3.00.0030.04713.49
5.2.170.0030.06311.06
5.2.160.0070.04711.06
5.2.150.0000.03711.15
5.2.140.0000.05711.19
5.2.130.0100.04711.15
5.2.120.0000.06711.04
5.2.110.0000.06011.15
5.2.100.0070.03711.09
5.2.90.0000.06011.02
5.2.80.0070.04311.09
5.2.70.0030.06711.16
5.2.60.0000.03711.09
5.2.50.0070.06010.85
5.2.40.0000.03711.07
5.2.30.0000.04310.97
5.2.20.0000.06010.81
5.2.10.0030.06310.91
5.2.00.0070.05710.64
5.1.60.0070.05010.02
5.1.50.0130.04310.02
5.1.40.0030.0379.93
5.1.30.0000.04010.36
5.1.20.0030.05710.31
5.1.10.0070.05010.08
5.1.00.0070.05310.05
5.0.50.0030.0438.58
5.0.40.0100.0338.49
5.0.30.0000.0478.21
5.0.20.0030.0438.30
5.0.10.0000.0478.21
5.0.00.0000.0478.21
4.4.90.0070.0277.30
4.4.80.0030.0307.30
4.4.70.0100.0277.30
4.4.60.0070.0237.30
4.4.50.0030.0237.30
4.4.40.0000.0507.30
4.4.30.0030.0377.30
4.4.20.0070.0307.30
4.4.10.0030.0377.30
4.4.00.0000.0607.30
4.3.110.0000.0377.30
4.3.100.0030.0307.30
4.3.90.0000.0377.30
4.3.80.0070.0377.30
4.3.70.0030.0337.30
4.3.60.0000.0177.30
4.3.50.0000.0407.30
4.3.40.0000.0577.30
4.3.30.0000.0337.30
4.3.20.0000.0377.30
4.3.10.0000.0377.30
4.3.00.0000.0237.30

preferences:
40.18 ms | 401 KiB | 5 Q