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 a2x(array $inner, SimpleXMLElement $node) { if (isset($inner['attributes'])) { $this->addAttribs($inner['attributes'], $node); unset($inner['attributes']); } if (count($inner)) { foreach ($inner as $key => $value) { if ($this->isEnumeration($value)) { foreach ($inner as $item) { $subNode = $node->addChild($this->lastKey); $this->a2x($item, $subNode); } } 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.0120.00318.68
8.3.50.0120.00922.17
8.3.40.0110.00719.17
8.3.30.0120.00419.08
8.3.20.0060.00319.02
8.3.10.0050.00321.36
8.3.00.0080.00023.65
8.2.180.0070.00716.88
8.2.170.0070.01122.96
8.2.160.0000.01320.63
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0040.00421.34
8.2.110.0070.00320.77
8.2.100.0040.00818.16
8.2.90.0000.00819.50
8.2.80.0000.00818.29
8.2.70.0040.00417.88
8.2.60.0060.00318.30
8.2.50.0030.00618.07
8.2.40.0040.00418.53
8.2.30.0040.00421.54
8.2.20.0070.00017.99
8.2.10.0080.00018.04
8.2.00.0030.00518.02
8.1.280.0040.01125.92
8.1.270.0050.00323.99
8.1.260.0100.01026.35
8.1.250.0040.00428.09
8.1.240.0060.00324.04
8.1.230.0090.00321.11
8.1.220.0030.00618.77
8.1.210.0030.00519.23
8.1.200.0040.00417.85
8.1.190.0000.00817.91
8.1.180.0000.00918.10
8.1.170.0040.00419.04
8.1.160.0040.00419.19
8.1.150.0000.00918.95
8.1.140.0040.00417.67
8.1.130.0000.00718.09
8.1.120.0000.00817.65
8.1.110.0000.00917.75
8.1.100.0040.00417.72
8.1.90.0050.00317.80
8.1.80.0040.00417.75
8.1.70.0030.00317.58
8.1.60.0080.00017.79
8.1.50.0030.00617.80
8.1.40.0040.00417.84
8.1.30.0080.00018.05
8.1.20.0030.00617.91
8.1.10.0040.00417.97
8.1.00.0090.00017.89
8.0.300.0040.00420.23
8.0.290.0040.00417.28
8.0.280.0040.00418.79
8.0.270.0080.00317.55
8.0.260.0070.00017.17
8.0.250.0040.00417.39
8.0.240.0030.00617.32
8.0.230.0090.00017.20
8.0.220.0030.00317.30
8.0.210.0030.00317.29
8.0.200.0030.00317.20
8.0.190.0040.00417.19
8.0.180.0040.00417.17
8.0.170.0030.00517.30
8.0.160.0070.00017.36
8.0.150.0000.00717.34
8.0.140.0050.00317.29
8.0.130.0030.00313.72
8.0.120.0040.00417.16
8.0.110.0050.00217.20
8.0.100.0040.00417.30
8.0.90.0040.00417.33
8.0.80.0060.01017.15
8.0.70.0050.00316.97
8.0.60.0000.00717.22
8.0.50.0050.00317.05
8.0.30.0120.00617.29
8.0.20.0120.00717.40
8.0.10.0030.00517.31
8.0.00.0060.01417.11
7.4.330.0050.00015.00
7.4.320.0000.00816.89
7.4.300.0000.00716.82
7.4.290.0030.00316.95
7.4.280.0000.00716.80
7.4.270.0070.00016.93
7.4.260.0000.00613.67
7.4.250.0080.00016.82
7.4.240.0030.00516.91
7.4.230.0030.00316.59
7.4.220.0030.01616.90
7.4.210.0060.00916.84
7.4.200.0030.00316.78
7.4.190.0000.00716.75
7.4.160.0090.00616.93
7.4.150.0180.00617.40
7.4.140.0080.01217.86
7.4.130.0090.01016.81
7.4.120.0060.01116.93
7.4.110.0030.01816.93
7.4.100.0040.01916.80
7.4.90.0100.01416.68
7.4.80.0000.01619.39
7.4.70.0100.00716.95
7.4.60.0130.00316.88
7.4.50.0060.00316.90
7.4.40.0100.00522.77
7.4.30.0100.01016.99
7.4.00.0120.00315.38
7.3.330.0030.00313.60
7.3.320.0000.00713.50
7.3.310.0000.00716.68
7.3.300.0070.00016.52
7.3.290.0070.01116.71
7.3.280.0060.01216.67
7.3.270.0060.01117.40
7.3.260.0130.00818.24
7.3.250.0040.01316.89
7.3.240.0080.00816.72
7.3.230.0080.00816.67
7.3.210.0150.00316.71
7.3.200.0080.01319.39
7.3.190.0030.01616.89
7.3.180.0170.00016.88
7.3.170.0090.00616.68
7.3.160.0090.00616.78
7.3.120.0060.01114.96
7.2.330.0120.00616.84
7.2.320.0130.01016.88
7.2.310.0130.01017.04
7.2.300.0090.00916.82
7.2.290.0080.00817.13
7.2.60.0130.00317.09
7.2.00.0000.01519.29
7.1.200.0090.00615.97
7.1.100.0100.00318.29
7.1.70.0030.00617.45
7.1.60.0070.01819.40
7.1.50.0150.00617.09
7.1.00.0000.03722.59
7.0.200.0000.00717.04
7.0.140.0000.07322.16
7.0.80.0730.05720.26
7.0.70.0500.04320.02
7.0.60.0470.05020.22
7.0.50.0030.07320.44
7.0.40.0100.07720.15
7.0.30.0030.08320.27
7.0.20.0000.06320.23
7.0.10.0130.04720.14
7.0.00.0130.05020.18
5.6.280.0030.07721.25
5.6.230.0030.08320.92
5.6.220.0000.08320.58
5.6.210.0130.06720.72
5.6.200.0100.08021.19
5.6.190.0100.08321.12
5.6.180.0130.08021.20
5.6.170.0100.05721.02
5.6.160.0000.05321.32
5.6.150.0170.08021.20
5.6.140.0130.07721.32
5.6.130.0030.07321.19
5.6.120.0100.07321.18
5.6.110.0070.07021.04
5.6.100.0200.07721.18
5.6.90.0170.08021.20
5.6.80.0100.08020.52
5.6.70.0100.07320.59
5.6.60.0100.07720.47
5.6.50.0100.07020.55
5.6.40.0030.06720.65
5.6.30.0070.08020.45
5.6.20.0030.04720.40
5.6.10.0100.07720.61
5.6.00.0070.07720.50
5.5.370.0030.08320.63
5.5.360.0130.07720.64
5.5.350.0100.08320.67
5.5.340.0130.05021.02
5.5.330.0100.07321.02
5.5.320.0230.03721.02
5.5.310.0130.07320.93
5.5.300.0100.07321.07
5.5.290.0030.04720.95
5.5.280.0030.07720.91
5.5.270.0070.08720.92
5.5.260.0100.04020.95
5.5.250.0100.07020.78
5.5.240.0100.04020.24
5.5.230.0130.08020.29
5.5.220.0000.08020.32
5.5.210.0170.07320.43
5.5.200.0100.06020.43
5.5.190.0100.05720.32
5.5.180.0130.07720.31
5.5.160.0070.08320.34
5.5.150.0100.07720.27
5.5.140.0070.05320.43
5.5.130.0070.05720.42
5.5.120.0100.03720.40
5.5.110.0200.07020.38
5.5.100.0030.06020.29
5.5.90.0070.08020.12
5.5.80.0100.05720.15
5.5.70.0130.07020.31
5.5.60.0070.04020.17
5.5.50.0100.07020.16
5.5.40.0100.07020.18
5.5.30.0030.05020.14
5.5.20.0070.07720.17
5.5.10.0000.08720.11
5.5.00.0230.06720.24
5.4.450.0100.07319.41
5.4.440.0070.05319.56
5.4.430.0030.08719.70
5.4.420.0100.06019.55
5.4.410.0070.04019.44
5.4.400.0100.04019.20
5.4.390.0200.03318.95
5.4.380.0130.07019.27
5.4.370.0000.08319.24
5.4.360.0170.06019.30
5.4.350.0100.07719.13
5.4.340.0030.05019.13
5.4.320.0130.05319.25
5.4.310.0170.07019.26
5.4.300.0030.06319.33
5.4.290.0100.03319.28
5.4.280.0030.05719.24
5.4.270.0030.05019.24
5.4.260.0100.05719.28
5.4.250.0070.07719.39
5.4.240.0100.07719.29
5.4.230.0100.08019.39
5.4.220.0030.08019.29
5.4.210.0000.05719.24
5.4.200.0070.04719.02
5.4.190.0170.06319.26
5.4.180.0100.07719.07
5.4.170.0100.05319.22
5.4.160.0030.05318.95
5.4.150.0070.08019.26
5.4.140.0130.06716.52
5.4.130.0030.06016.54
5.4.120.0000.07716.65
5.4.110.0100.06316.52
5.4.100.0100.06316.70
5.4.90.0030.05716.61
5.4.80.0130.06716.56
5.4.70.0100.07016.75
5.4.60.0070.07716.54
5.4.50.0130.06716.64
5.4.40.0130.06316.56
5.4.30.0170.06316.64
5.4.20.0000.06316.61
5.4.10.0070.06316.50
5.4.00.0030.05016.03
5.3.290.0030.08014.63
5.3.280.0070.07314.53
5.3.270.0070.08014.57
5.3.260.0030.06714.60
5.3.250.0030.08014.44
5.3.240.0130.07014.57
5.3.230.0100.04014.43
5.3.220.0070.07314.56
5.3.210.0070.05714.53
5.3.200.0070.07714.42
5.3.190.0030.04714.48
5.3.180.0200.07014.43
5.3.170.0000.06714.39
5.3.160.0100.07714.47
5.3.150.0070.07314.39
5.3.140.0030.05014.39
5.3.130.0100.07014.48
5.3.120.0130.05314.43
5.3.110.0100.07014.50
5.3.100.0070.07714.02
5.3.90.0070.04313.98
5.3.80.0130.03713.99
5.3.70.0030.04013.98
5.3.60.0070.06714.00
5.3.50.0100.06313.85
5.3.40.0030.07713.90
5.3.30.0170.06713.77
5.3.20.0100.05713.65
5.3.10.0130.06713.62
5.3.00.0100.07013.49
5.2.170.0200.04011.87
5.2.160.0030.06011.87
5.2.150.0070.06011.87
5.2.140.0070.06011.87
5.2.130.0030.03711.87
5.2.120.0100.05711.87
5.2.110.0030.04711.87
5.2.100.0000.06011.87
5.2.90.0000.06711.87
5.2.80.0070.05311.87
5.2.70.0030.05711.87
5.2.60.0100.05011.87
5.2.50.0070.05011.87
5.2.40.0000.03311.87
5.2.30.0030.06711.87
5.2.20.0100.05711.87
5.2.10.0070.03711.87
5.2.00.0030.06311.87
5.1.60.0030.05011.87
5.1.50.0000.05711.87
5.1.40.0030.04011.87
5.1.30.0030.05311.87
5.1.20.0070.05711.87
5.1.10.0030.05711.87
5.1.00.0030.04311.87
5.0.50.0070.03011.87
5.0.40.0030.03011.87
5.0.30.0030.06311.87
5.0.20.0000.04311.87
5.0.10.0000.03311.87
5.0.00.0030.06011.87
4.4.90.0030.03711.87
4.4.80.0070.03011.87
4.4.70.0100.02711.87
4.4.60.0030.02711.87
4.4.50.0070.02311.87
4.4.40.0030.05311.87
4.4.30.0030.03311.87
4.4.20.0070.03311.87
4.4.10.0030.02311.87
4.4.00.0000.05711.87
4.3.110.0030.03311.87
4.3.100.0000.03011.87
4.3.90.0000.03711.87
4.3.80.0030.04011.87
4.3.70.0030.03711.87
4.3.60.0000.03711.87
4.3.50.0000.03011.87
4.3.40.0000.04311.87
4.3.30.0000.04011.87
4.3.20.0000.03311.87
4.3.10.0030.02711.87
4.3.00.0000.03311.87

preferences:
69.7 ms | 401 KiB | 5 Q