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($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) { 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)
8.3.60.0070.01118.68
8.3.50.0100.01021.39
8.3.40.0000.02219.17
8.3.30.0040.01219.10
8.3.20.0040.00419.15
8.3.10.0030.00620.78
8.3.00.0080.00417.88
8.2.180.0180.00017.00
8.2.170.0090.00922.96
8.2.160.0070.00722.35
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0050.00221.12
8.2.110.0070.00321.27
8.2.100.0060.00618.28
8.2.90.0000.00819.58
8.2.80.0030.00518.30
8.2.70.0040.00418.00
8.2.60.0000.00818.41
8.2.50.0030.00518.41
8.2.40.0050.00318.59
8.2.30.0080.00020.24
8.2.20.0030.00518.02
8.2.10.0040.00418.03
8.2.00.0030.00618.05
8.1.280.0090.00625.92
8.1.270.0030.00623.99
8.1.260.0080.00026.35
8.1.250.0060.00328.09
8.1.240.0050.00522.71
8.1.230.0080.00321.29
8.1.220.0040.00418.77
8.1.210.0080.00019.27
8.1.200.0060.00317.63
8.1.190.0040.00417.89
8.1.180.0000.00818.10
8.1.170.0030.00519.21
8.1.160.0050.00319.24
8.1.150.0040.00418.94
8.1.140.0000.00817.73
8.1.130.0030.00318.11
8.1.120.0080.00017.75
8.1.110.0050.00317.86
8.1.100.0000.00717.82
8.1.90.0030.00517.68
8.1.80.0100.00017.68
8.1.70.0000.00717.79
8.1.60.0000.00917.79
8.1.50.0050.00317.83
8.1.40.0040.00417.86
8.1.30.0040.00417.86
8.1.20.0000.00817.93
8.1.10.0040.00417.91
8.1.00.0030.00517.82
8.0.300.0000.00720.46
8.0.290.0030.00617.13
8.0.280.0030.00318.77
8.0.270.0000.00717.58
8.0.260.0070.00018.91
8.0.250.0040.00417.27
8.0.240.0060.00317.37
8.0.230.0040.00417.39
8.0.220.0040.00717.34
8.0.210.0000.00817.31
8.0.200.0000.00717.21
8.0.190.0040.00417.43
8.0.180.0050.00317.25
8.0.170.0040.00417.16
8.0.160.0000.00717.38
8.0.150.0000.00817.17
8.0.140.0040.00417.19
8.0.130.0060.00013.72
8.0.120.0000.00717.17
8.0.110.0000.00717.21
8.0.100.0040.00417.34
8.0.90.0080.00017.07
8.0.80.0090.00617.31
8.0.70.0080.00017.23
8.0.60.0070.00017.04
8.0.50.0040.00417.02
8.0.30.0110.00817.49
8.0.20.0100.01017.49
8.0.10.0000.00717.43
8.0.00.0050.01417.27
7.4.330.0030.00315.00
7.4.320.0030.00316.89
7.4.300.0030.00316.81
7.4.290.0000.00717.01
7.4.280.0060.00316.84
7.4.270.0000.00816.88
7.4.260.0060.00013.69
7.4.250.0040.00416.89
7.4.240.0050.00316.72
7.4.230.0050.00216.73
7.4.220.0140.00616.89
7.4.210.0060.00816.96
7.4.200.0030.00316.96
7.4.190.0040.00416.97
7.4.160.0030.01316.94
7.4.150.0060.01117.40
7.4.140.0050.01217.43
7.4.130.0050.01316.81
7.4.120.0170.00516.96
7.4.110.0070.01016.75
7.4.100.0070.01116.89
7.4.90.0070.01116.98
7.4.80.0120.00619.03
7.4.70.0100.00616.75
7.4.60.0100.00616.81
7.4.50.0000.00516.51
7.4.40.0170.00222.27
7.4.30.0100.00616.68
7.4.00.0080.01015.12
7.3.330.0000.00513.66
7.3.320.0030.00313.68
7.3.310.0040.00416.64
7.3.300.0030.00316.75
7.3.290.0030.01016.69
7.3.280.0090.01316.70
7.3.270.0100.00717.40
7.3.260.0100.01018.24
7.3.250.0150.00316.69
7.3.240.0080.00916.70
7.3.230.0110.01116.77
7.3.210.0110.00716.70
7.3.200.0150.00719.39
7.3.190.0120.00617.02
7.3.180.0080.01116.68
7.3.170.0140.00316.80
7.3.160.0090.00616.91
7.3.120.0060.01014.93
7.3.110.0070.01114.95
7.3.100.0120.00315.09
7.3.90.0000.00914.94
7.3.80.0070.01015.06
7.3.70.0110.00015.07
7.3.60.0030.01415.18
7.3.50.0070.00715.00
7.3.40.0040.01115.15
7.3.30.0070.01015.17
7.3.20.0030.01016.69
7.3.10.0090.00916.71
7.3.00.0110.00616.50
7.2.330.0130.00316.93
7.2.320.0120.01217.07
7.2.310.0040.02117.04
7.2.300.0110.00717.03
7.2.290.0100.00617.05
7.2.250.0140.00715.62
7.2.240.0030.01715.24
7.2.230.0040.01115.34
7.2.220.0030.01015.26
7.2.210.0040.01115.12
7.2.200.0030.01315.31
7.2.190.0070.00315.17
7.2.180.0040.01415.17
7.2.170.0060.00615.08
7.2.130.0160.00816.68
7.2.120.0290.00316.46
7.2.110.0170.00716.45
7.2.100.0240.00716.45
7.2.90.0310.00416.61
7.2.80.0340.00716.55
7.2.70.0340.00316.61
7.2.60.0230.00316.96
7.2.50.0200.00616.69
7.2.40.0140.00717.01
7.2.30.0140.01316.75
7.2.20.0180.00416.43
7.2.10.0260.01316.89
7.2.00.0190.00918.21
7.1.330.0060.00815.75
7.1.320.0000.01216.03
7.1.310.0060.00315.70
7.1.300.0030.01015.79
7.1.290.0040.00816.02
7.1.280.0030.01216.00
7.1.270.0100.00616.02
7.1.260.0040.01116.03
7.1.250.0200.01115.80
7.1.200.0220.00315.97
7.1.100.0040.00418.50
7.1.70.0090.00617.30
7.1.60.0100.01619.40
7.1.50.0060.00916.91
7.1.00.0100.06322.59
7.0.200.0200.00716.75
7.0.140.0030.07022.16
7.0.60.0100.07720.04
7.0.50.0070.08318.09
7.0.40.0130.05317.98
7.0.30.0000.08317.93
7.0.20.0100.08017.84
7.0.10.0200.05317.86
7.0.00.0170.03317.88
5.6.210.0130.08020.65
5.6.200.0170.07318.31
5.6.190.0170.07718.43
5.6.180.0100.07718.30
5.6.170.0030.08318.40
5.6.160.0070.04018.41
5.6.150.0030.04018.41
5.6.140.0000.08318.38
5.6.130.0070.08718.28
5.6.120.0130.07018.28
5.6.110.0130.07718.43
5.6.100.0100.07018.38
5.6.90.0030.07718.30
5.6.80.0100.07717.76
5.6.70.0070.04717.76
5.6.60.0030.06317.80
5.6.50.0100.07317.72
5.6.40.0130.08017.63
5.6.30.0030.07317.64
5.6.20.0070.04717.69
5.6.10.0130.07717.67
5.6.00.0030.06317.63
5.5.350.0170.07320.61
5.5.340.0070.08018.13
5.5.330.0100.07018.09
5.5.320.0170.07018.05
5.5.310.0130.05018.01
5.5.300.0030.06018.22
5.5.290.0100.08318.21
5.5.280.0030.08318.20
5.5.270.0030.04718.17
5.5.260.0200.07018.05
5.5.250.0000.06317.94
5.5.240.0070.05317.52
5.5.230.0100.06717.56
5.5.220.0100.04717.48
5.5.210.0100.07717.51
5.5.200.0030.07717.58
5.5.190.0070.06017.53
5.5.180.0100.07317.48
5.5.160.0100.07317.40
5.5.150.0070.07317.45
5.5.140.0070.08317.39
5.5.130.0100.07717.39
5.5.120.0030.08017.57
5.5.110.0030.04717.52
5.5.100.0100.07017.31
5.5.90.0100.04717.36
5.5.80.0030.05717.30
5.5.70.0170.07017.35
5.5.60.0070.05017.39
5.5.50.0070.05317.45
5.5.40.0070.04717.47
5.5.30.0100.03317.38
5.5.20.0000.08017.29
5.5.10.0030.06017.29
5.5.00.0100.07317.36
5.4.450.0070.04719.51
5.4.440.0000.06019.29
5.4.430.0100.06719.36
5.4.420.0100.05719.54
5.4.410.0070.07019.32
5.4.400.0030.04319.07
5.4.390.0130.07019.23
5.4.380.0200.05719.22
5.4.370.0070.06319.28
5.4.360.0030.05319.24
5.4.350.0300.04319.26
5.4.340.0070.05019.06
5.4.320.0030.05019.05
5.4.310.0070.06319.13
5.4.300.0130.05319.21
5.4.290.0030.08319.02
5.4.280.0030.05719.21
5.4.270.0070.07318.98
5.4.260.0070.07318.96
5.4.250.0100.07019.16
5.4.240.0100.03319.27
5.4.230.0000.06319.17
5.4.220.0000.05319.21
5.4.210.0070.08019.13
5.4.200.0070.03719.02
5.4.190.0030.04019.21
5.4.180.0070.04018.95
5.4.170.0100.04719.11
5.4.160.0030.04019.22
5.4.150.0130.07019.26
5.4.140.0030.07716.57
5.4.130.0070.06716.54
5.4.120.0170.05716.47
5.4.110.0070.07716.53
5.4.100.0000.08716.77
5.4.90.0070.08016.78
5.4.80.0030.04716.52
5.4.70.0030.03716.47
5.4.60.0100.06716.47
5.4.50.0000.05716.75
5.4.40.0030.04016.52
5.4.30.0100.03316.52
5.4.20.0130.05716.53
5.4.10.0130.07016.52
5.4.00.0070.07316.05
5.3.290.0070.06014.62
5.3.280.0030.08014.57
5.3.270.0070.07714.68
5.3.260.0000.08014.59
5.3.250.0070.07714.53
5.3.240.0130.06714.59
5.3.230.0100.06014.38
5.3.220.0030.04714.53
5.3.210.0070.04014.53
5.3.200.0070.06314.54
5.3.190.0170.07014.65
5.3.180.0170.06714.52
5.3.170.0070.07714.54
5.3.160.0030.08314.34
5.3.150.0100.07014.54
5.3.140.0130.03314.49
5.3.130.0030.08314.41
5.3.120.0030.08314.40
5.3.110.0030.08014.32
5.3.100.0170.06713.89
5.3.90.0070.07713.98
5.3.80.0030.07013.77
5.3.70.0030.06013.87
5.3.60.0000.05313.93
5.3.50.0100.07013.86
5.3.40.0030.06313.92
5.3.30.0100.07013.88
5.3.20.0130.05713.64
5.3.10.0100.06713.66
5.3.00.0030.07013.57
5.2.170.0000.06711.04
5.2.160.0030.06311.29
5.2.150.0030.04711.14
5.2.140.0000.06711.18
5.2.130.0130.05311.08
5.2.120.0030.04011.25
5.2.110.0070.04311.04
5.2.100.0030.05011.08
5.2.90.0070.05311.01
5.2.80.0030.06711.01
5.2.70.0070.06011.08
5.2.60.0100.05011.01
5.2.50.0070.06010.85
5.2.40.0030.05710.91
5.2.30.0070.04011.11
5.2.20.0030.03710.93
5.2.10.0000.04710.81
5.2.00.0070.03310.64
5.1.60.0030.0539.93
5.1.50.0070.03710.04
5.1.40.0070.03710.00
5.1.30.0030.03310.28
5.1.20.0030.04310.39
5.1.10.0070.04710.07
5.1.00.0100.05010.04
5.0.50.0100.0178.73
5.0.40.0000.0278.73
5.0.30.0030.0578.73
5.0.20.0070.0408.73
5.0.10.0070.0308.73
5.0.00.0000.0538.73
4.4.90.0030.0408.73
4.4.80.0030.0338.73
4.4.70.0000.0408.73
4.4.60.0030.0278.73
4.4.50.0000.0338.73
4.4.40.0000.0538.73
4.4.30.0000.0208.73
4.4.20.0000.0208.73
4.4.10.0030.0238.73
4.4.00.0000.0508.73
4.3.110.0070.0338.73
4.3.100.0000.0278.73
4.3.90.0070.0308.73
4.3.80.0030.0308.73
4.3.70.0000.0278.73
4.3.60.0070.0308.73
4.3.50.0100.0178.73
4.3.40.0000.0378.73
4.3.30.0000.0308.73
4.3.20.0000.0208.73
4.3.10.0070.0138.73
4.3.00.0030.0308.73

preferences:
57.67 ms | 400 KiB | 5 Q