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; return $dom->loadXML($xml->asXML())->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.0070.00717.00
8.3.50.0060.01117.84
8.3.40.0130.00319.32
8.3.30.0060.01319.03
8.3.20.0040.00419.20
8.3.10.0030.00620.89
8.3.00.0090.00019.75
8.2.180.0100.00617.13
8.2.170.0070.01522.96
8.2.160.0030.01420.77
8.2.150.0040.01124.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0030.00621.14
8.2.110.0060.00321.41
8.2.100.0060.00618.15
8.2.90.0060.00319.91
8.2.80.0000.00819.70
8.2.70.0040.00417.88
8.2.60.0040.00418.18
8.2.50.0000.00818.07
8.2.40.0000.00818.66
8.2.30.0030.00618.36
8.2.20.0030.00619.86
8.2.10.0000.00718.12
8.2.00.0000.00818.17
8.1.280.0040.01125.92
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00622.85
8.1.230.0100.00321.27
8.1.220.0000.00818.16
8.1.210.0040.00419.14
8.1.200.0000.01217.72
8.1.190.0030.00517.88
8.1.180.0050.00318.10
8.1.170.0050.00319.25
8.1.160.0000.00819.27
8.1.150.0080.00019.02
8.1.140.0000.00817.83
8.1.130.0080.00017.75
8.1.120.0000.00817.82
8.1.110.0080.00017.83
8.1.100.0040.00417.83
8.1.90.0000.00817.80
8.1.80.0040.00417.83
8.1.70.0000.00717.79
8.1.60.0000.01017.93
8.1.50.0030.00617.81
8.1.40.0000.00817.68
8.1.30.0030.00617.96
8.1.20.0000.00817.86
8.1.10.0060.00317.93
8.1.00.0030.00517.89
8.0.300.0040.00420.23
8.0.290.0000.00817.13
8.0.280.0070.00018.70
8.0.270.0040.00417.65
8.0.260.0070.00017.09
8.0.250.0040.00417.21
8.0.240.0000.00717.36
8.0.230.0000.00717.22
8.0.220.0000.00717.14
8.0.210.0040.00417.38
8.0.200.0040.00417.39
8.0.190.0050.00217.42
8.0.180.0040.00417.29
8.0.170.0030.00617.27
8.0.160.0070.00017.29
8.0.150.0060.00317.25
8.0.140.0080.00017.28
8.0.130.0000.00613.71
8.0.120.0050.00317.34
8.0.110.0000.00717.32
8.0.100.0000.00817.35
8.0.90.0040.00417.35
8.0.80.0070.01017.34
8.0.70.0040.00417.00
8.0.60.0000.00817.07
8.0.50.0000.00817.11
8.0.30.0130.00317.73
8.0.20.0080.01317.25
8.0.10.0000.00817.26
8.0.00.0160.00917.02
7.4.330.0050.00013.43
7.4.320.0030.00316.85
7.4.300.0030.00316.94
7.4.290.0000.00716.83
7.4.280.0050.00316.88
7.4.270.0000.00816.91
7.4.260.0050.00213.62
7.4.250.0060.00316.76
7.4.240.0030.00316.96
7.4.230.0040.00416.92
7.4.220.0030.01416.90
7.4.210.0070.00716.88
7.4.200.0040.00416.68
7.4.190.0040.00416.82
7.4.160.0000.01616.92
7.4.150.0120.00616.95
7.4.140.0120.00616.75
7.4.130.0120.00616.88
7.4.120.0070.01116.95
7.4.110.0060.01216.98
7.4.100.0060.01216.66
7.4.90.0100.01017.06
7.4.80.0090.01016.91
7.4.70.0100.00716.91
7.4.60.0070.01016.89
7.4.50.0060.00316.81
7.4.40.0030.01016.52
7.4.30.0060.01116.65
7.4.10.0070.01315.06
7.4.00.0080.00714.88
7.3.330.0030.00313.52
7.3.320.0000.00513.54
7.3.310.0040.00416.82
7.3.300.0030.00316.82
7.3.290.0080.00816.74
7.3.280.0100.00816.73
7.3.270.0150.00316.91
7.3.260.0090.00917.07
7.3.250.0110.00816.83
7.3.240.0000.01716.95
7.3.230.0030.01316.96
7.3.210.0130.01016.77
7.3.200.0030.01719.39
7.3.190.0070.01116.73
7.3.180.0100.00716.86
7.3.170.0000.01816.86
7.3.160.0140.00316.79
7.3.130.0070.01214.73
7.3.120.0090.00715.12
7.3.110.0020.01715.12
7.3.100.0060.00715.26
7.3.90.0050.01314.96
7.3.80.0050.00615.17
7.3.70.0100.00314.87
7.3.60.0010.01015.07
7.3.50.0100.00314.87
7.3.40.0030.00714.96
7.3.30.0130.00015.10
7.3.20.0020.01116.89
7.3.10.0070.00716.83
7.3.00.0040.00916.71
7.2.330.0090.00917.20
7.2.320.0040.01316.80
7.2.310.0100.01316.91
7.2.300.0090.01017.23
7.2.290.0090.00916.87
7.2.260.0050.01415.36
7.2.250.0100.00715.13
7.2.240.0050.01115.34
7.2.230.0050.01015.00
7.2.220.0070.00615.32
7.2.210.0030.01015.13
7.2.200.0070.00415.15
7.2.190.0080.00615.30
7.2.180.0060.00915.13
7.2.170.0050.00815.20
7.2.160.0090.00315.34
7.2.150.0080.00517.10
7.2.140.0060.00917.00
7.2.130.0020.01317.06
7.2.120.0070.00817.06
7.2.110.0030.01017.02
7.2.100.0020.01217.05
7.2.90.0070.00517.18
7.2.80.0070.01017.08
7.2.70.0030.01017.12
7.2.60.0040.01016.97
7.2.50.0020.01117.09
7.2.40.0070.00517.07
7.2.30.0070.00717.11
7.2.20.0050.00816.98
7.2.10.0090.00317.06
7.2.00.0030.00817.83
7.1.330.0100.00516.13
7.1.320.0060.00716.01
7.1.310.0070.00615.94
7.1.300.0030.01015.93
7.1.290.0050.00716.01
7.1.280.0080.00615.85
7.1.270.0090.00415.73
7.1.260.0070.00515.95
7.1.250.0050.01115.82
7.1.240.0040.00815.87
7.1.230.0050.00815.93
7.1.220.0050.00615.79
7.1.210.0030.01016.00
7.1.200.0090.00415.87
7.1.190.0080.00615.87
7.1.180.0050.00615.76
7.1.170.0070.00415.85
7.1.160.0030.01015.91
7.1.150.0030.01015.85
7.1.140.0050.00715.91
7.1.130.0050.00715.88
7.1.120.0050.00815.94
7.1.110.0030.01215.95
7.1.100.0020.01016.73
7.1.90.0030.01015.87
7.1.80.0020.01115.86
7.1.70.0050.00616.34
7.1.60.0060.00817.05
7.1.50.0090.00616.19
7.1.40.0050.00815.76
7.1.30.0070.00715.93
7.1.20.0060.00715.76
7.1.10.0050.01015.84
7.1.00.0050.03018.13
7.0.330.0070.00815.68
7.0.320.0060.00915.51
7.0.310.0050.00615.46
7.0.300.0030.00815.50
7.0.290.0060.00615.49
7.0.280.0030.01015.65
7.0.270.0020.01015.63
7.0.260.0020.01115.61
7.0.250.0050.00915.71
7.0.240.0070.00215.41
7.0.230.0020.00815.59
7.0.220.0070.00415.55
7.0.210.0050.00815.41
7.0.200.0120.00715.45
7.0.190.0010.00715.59
7.0.180.0070.00115.71
7.0.170.0030.00815.44
7.0.160.0030.00715.60
7.0.150.0070.00715.63
7.0.140.0090.02517.81
7.0.130.0040.00515.62
7.0.120.0040.03117.78
7.0.110.0060.00815.64
7.0.100.0040.00915.59
7.0.90.0050.02317.10
7.0.80.0040.02017.11
7.0.70.0030.01917.04
7.0.60.0040.02017.13
7.0.50.0090.01717.21
7.0.40.0050.02015.83
7.0.30.0070.02915.90
7.0.20.0060.01815.91
7.0.10.0060.02915.93
7.0.00.0040.01915.80
5.6.400.0060.00614.87
5.6.390.0040.01314.72
5.6.380.0050.00815.02
5.6.370.0030.01114.66
5.6.360.0050.00914.69
5.6.350.0030.00814.89
5.6.340.0080.00614.85
5.6.330.0040.01114.74
5.6.320.0070.00414.86
5.6.310.0070.00814.69
5.6.300.0090.00714.82
5.6.290.0020.00814.89
5.6.280.0050.03016.90
5.6.270.0100.00614.71
5.6.260.0030.01014.72
5.6.250.0060.00814.72
5.6.240.0130.01316.71
5.6.230.0040.02016.71
5.6.220.0040.02016.61
5.6.210.0050.02316.77
5.6.200.0070.02016.84
5.6.190.0050.02416.86
5.6.180.0030.02016.87
5.6.170.0070.01916.73
5.6.160.0070.01616.82
5.6.150.0030.02216.79
5.6.140.0050.01816.90
5.6.130.0030.02216.80
5.6.120.0070.01816.79
5.6.110.0030.02216.76
5.6.100.0040.02016.97
5.6.90.0030.02316.85
5.6.80.0060.01816.61
5.6.70.0100.02116.56
5.6.60.0070.02916.60
5.6.50.0080.02016.56
5.6.40.0090.01916.57
5.6.30.0150.01516.61
5.6.20.0060.02416.62
5.6.10.0100.02716.50
5.6.00.0060.02316.54
5.5.380.0040.01916.55
5.5.370.0030.02116.61
5.5.360.0050.01916.67
5.5.350.0060.02016.70
5.5.340.0070.02416.73
5.5.330.0040.01716.71
5.5.320.0100.01716.66
5.5.310.0070.02016.72
5.5.300.0050.01716.69
5.5.290.0070.01816.71
5.5.280.0070.01816.65
5.5.270.0030.02516.78
5.5.260.0080.02316.71
5.5.250.0020.02016.70
5.5.240.0070.02816.61
5.5.230.0080.03416.46
5.5.220.0050.03216.46
5.5.210.0040.02016.56
5.5.200.0090.02016.55
5.5.190.0070.03216.60
5.5.180.0030.03516.50
5.5.170.0040.01114.50
5.5.160.0080.02916.64
5.5.150.0070.03116.62
5.5.140.0040.02316.60
5.5.130.0070.03116.53
5.5.120.0050.02516.59
5.5.110.0030.03316.39
5.5.100.0030.03716.49
5.5.90.0030.03016.64
5.5.80.0100.01816.56
5.5.70.0130.02416.49
5.5.60.0080.02816.41
5.5.50.0060.02916.49
5.5.40.0080.03416.45
5.5.30.0080.03116.52
5.5.20.0080.02616.42
5.5.10.0080.02116.26
5.5.00.0060.02816.49
5.4.450.0110.01615.12
5.4.440.0060.02314.87
5.4.430.0050.02014.92
5.4.420.0050.02714.89
5.4.410.0020.01714.84
5.4.400.0070.01614.83
5.4.390.0040.03314.77
5.4.380.0070.01814.84
5.4.370.0080.01814.88
5.4.360.0080.01814.76
5.4.350.0080.03014.81
5.4.340.0100.02914.90
5.4.330.0070.00912.58
5.4.320.0060.01914.83
5.4.310.0060.01814.81
5.4.300.0040.03414.86
5.4.290.0050.02214.91
5.4.280.0090.02414.82
5.4.270.0080.02214.80
5.4.260.0070.02614.83
5.4.250.0090.02414.75
5.4.240.0110.01814.77
5.4.230.0080.02814.82
5.4.220.0080.02014.82
5.4.210.0100.01614.79
5.4.200.0070.02814.82
5.4.190.0090.02914.84
5.4.180.0050.03114.77
5.4.170.0080.02814.90
5.4.160.0080.03114.79
5.4.150.0020.03414.85
5.4.140.0100.02313.88
5.4.130.0080.02613.96
5.4.120.0040.02213.86
5.4.110.0090.02713.91
5.4.100.0080.02613.95
5.4.90.0080.03113.95
5.4.80.0070.02613.98
5.4.70.0080.02813.98
5.4.60.0090.01913.92
5.4.50.0090.02613.93
5.4.40.0060.02313.97
5.4.30.0080.02814.05
5.4.20.0070.03213.89
5.4.10.0070.03014.01
5.4.00.0080.02013.74
5.3.290.0050.02712.94
5.3.280.0090.02912.87
5.3.270.0080.03012.90
5.3.260.0070.02512.89
5.3.250.0110.01412.89
5.3.240.0080.01812.90
5.3.230.0080.02712.88
5.3.220.0070.02012.87
5.3.210.0100.02712.85
5.3.200.0060.03112.89
5.3.190.0060.02912.85
5.3.180.0060.03012.83
5.3.170.0050.02912.92
5.3.160.0070.02812.86
5.3.150.0030.02312.93
5.3.140.0090.02512.88
5.3.130.0060.02712.89
5.3.120.0070.02312.84
5.3.110.0040.03212.86
5.3.100.0040.02912.68
5.3.90.0070.01812.65
5.3.80.0040.03212.70
5.3.70.0020.02712.63
5.3.60.0090.01512.67
5.3.50.0070.01712.68
5.3.40.0030.02512.62
5.3.30.0040.02112.63
5.3.20.0060.01612.59
5.3.10.0060.01512.51
5.3.00.0050.03012.56
5.2.170.0100.06011.09
5.2.160.0030.05011.01
5.2.150.0100.04711.18
5.2.140.0000.03311.13
5.2.130.0000.04010.96
5.2.120.0100.02310.96
5.2.110.0100.04311.15
5.2.100.0000.03710.96
5.2.90.0030.06011.11
5.2.80.0070.06311.12
5.2.70.0030.05311.09
5.2.60.0030.05711.05
5.2.50.0030.03710.83
5.2.40.0100.05710.84
5.2.30.0030.04010.96
5.2.20.0030.03710.90
5.2.10.0070.05310.89
5.2.00.0070.03310.74
5.1.60.0100.04310.55
5.1.50.0030.05010.55
5.1.40.0070.03010.55
5.1.30.0070.05010.55
5.1.20.0100.01710.55
5.1.10.0100.05310.55
5.1.00.0130.05310.55
5.0.50.0030.04710.55
5.0.40.0030.04310.55
5.0.30.0030.04310.55
5.0.20.0000.02710.55
5.0.10.0130.02010.55
5.0.00.0100.05310.55
4.4.90.0030.03310.55
4.4.80.0000.02710.55
4.4.70.0000.04010.55
4.4.60.0030.03310.55
4.4.50.0030.03310.55
4.4.40.0000.02710.55
4.4.30.0030.03010.55
4.4.20.0000.03710.55
4.4.10.0000.02010.55
4.4.00.0070.03710.55
4.3.110.0030.03710.55
4.3.100.0100.02710.55
4.3.90.0070.03310.55
4.3.80.0070.03010.55
4.3.70.0000.02710.55
4.3.60.0070.02010.55
4.3.50.0000.03710.55
4.3.40.0070.04710.55
4.3.30.0030.03310.55
4.3.20.0000.02310.55
4.3.10.0000.03310.55
4.3.00.0030.02310.55

preferences:
52.97 ms | 400 KiB | 5 Q