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->a2x(current($this->context), $this->res)->asXML(); } 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 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.70.0130.00318.53
8.3.60.0140.00716.88
8.3.50.0080.00922.19
8.3.40.0090.00619.10
8.3.30.0000.01419.34
8.3.20.0080.00020.54
8.3.10.0040.00423.90
8.3.00.0000.00821.00
8.2.190.0070.01116.88
8.2.180.0160.00619.04
8.2.170.0090.00622.96
8.2.160.0030.01022.38
8.2.150.0090.00024.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00422.45
8.2.110.0080.00022.50
8.2.100.0080.00418.16
8.2.90.0040.00419.51
8.2.80.0000.00818.25
8.2.70.0080.00018.00
8.2.60.0070.00418.29
8.2.50.0000.00818.07
8.2.40.0000.01018.47
8.2.30.0040.00418.45
8.2.20.0000.00818.22
8.2.10.0030.00618.10
8.2.00.0000.00818.15
8.1.280.0090.00625.92
8.1.270.0040.00424.14
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0030.00624.04
8.1.230.0060.00619.54
8.1.220.0080.00018.03
8.1.210.0040.00418.77
8.1.200.0090.00017.73
8.1.190.0040.00418.02
8.1.180.0000.00818.10
8.1.170.0030.00618.91
8.1.160.0050.00222.33
8.1.150.0040.00418.96
8.1.140.0040.00417.75
8.1.130.0000.00718.19
8.1.120.0090.00017.73
8.1.110.0080.00017.64
8.1.100.0040.00417.86
8.1.90.0040.00417.84
8.1.80.0030.00317.88
8.1.70.0000.00817.76
8.1.60.0090.00017.79
8.1.50.0030.00617.71
8.1.40.0000.00817.74
8.1.30.0000.01017.97
8.1.20.0080.00017.81
8.1.10.0030.00617.77
8.1.00.0050.00317.87
8.0.300.0000.00918.77
8.0.290.0040.00417.55
8.0.280.0040.00418.74
8.0.270.0000.00717.57
8.0.260.0030.00317.18
8.0.250.0000.00717.34
8.0.240.0000.00817.21
8.0.230.0050.00317.36
8.0.220.0000.00717.28
8.0.210.0030.00317.26
8.0.200.0030.00317.22
8.0.190.0040.00417.37
8.0.180.0040.00417.30
8.0.170.0060.00317.18
8.0.160.0050.00217.12
8.0.150.0000.00817.03
8.0.140.0050.00317.11
8.0.130.0000.00613.70
8.0.120.0030.00517.22
8.0.110.0080.00017.20
8.0.100.0000.00817.05
8.0.90.0000.00917.21
8.0.80.0090.00617.13
8.0.70.0060.00317.29
8.0.60.0000.00717.11
8.0.50.0040.00417.31
8.0.30.0150.00517.37
8.0.20.0110.00817.59
8.0.10.0040.00417.32
8.0.00.0120.00617.08
7.4.330.0000.00515.39
7.4.320.0000.00616.89
7.4.300.0000.00816.92
7.4.290.0030.00316.70
7.4.280.0030.00516.85
7.4.270.0000.00716.84
7.4.260.0000.00716.71
7.4.250.0080.00016.76
7.4.240.0040.00416.96
7.4.230.0070.00016.61
7.4.220.0060.01216.91
7.4.210.0080.01316.83
7.4.200.0040.00416.62
7.4.190.0040.00416.76
7.4.160.0100.01316.86
7.4.150.0120.00917.40
7.4.140.0090.00917.86
7.4.130.0090.00916.73
7.4.120.0090.01016.80
7.4.110.0070.01016.92
7.4.100.0160.00716.70
7.4.90.0120.00616.61
7.4.80.0070.01016.85
7.4.70.0090.00916.85
7.4.60.0070.00716.91
7.4.50.0000.01016.85
7.4.40.0030.00822.77
7.4.30.0070.01016.95
7.4.00.0000.01415.26
7.3.330.0000.00513.63
7.3.320.0000.00513.50
7.3.310.0070.00016.75
7.3.300.0030.00316.65
7.3.290.0090.00616.80
7.3.280.0100.00616.72
7.3.270.0090.00917.40
7.3.260.0120.00616.85
7.3.250.0120.00616.70
7.3.240.0130.00716.92
7.3.230.0120.00916.95
7.3.210.0130.00316.84
7.3.200.0080.01019.39
7.3.190.0120.00616.70
7.3.180.0110.00616.67
7.3.170.0100.01017.01
7.3.160.0110.00516.80
7.3.120.0060.00915.10
7.2.330.0050.01317.14
7.2.320.0160.00317.21
7.2.310.0090.00916.97
7.2.300.0070.01117.01
7.2.290.0030.01316.89
7.2.60.0030.00916.89
7.1.200.0040.00715.95
7.1.70.0040.00417.27
7.1.60.0070.01819.27
7.1.50.0030.01417.08
7.1.00.0070.07322.54
7.0.200.0080.00416.95
7.0.140.0100.06722.16
7.0.90.0070.08720.32
7.0.80.0030.05720.25
7.0.70.0070.07320.21
7.0.60.0030.04320.14
7.0.50.0030.05720.47
7.0.40.0030.05720.19
7.0.30.0100.03720.19
7.0.20.0030.04320.19
7.0.10.0030.04320.12
7.0.00.0200.03320.16
5.6.280.0030.07321.06
5.6.240.0070.05020.89
5.6.230.0070.07020.66
5.6.220.0030.04720.75
5.6.210.0030.04321.03
5.6.200.0030.04321.27
5.6.190.0030.04321.32
5.6.180.0000.04321.32
5.6.170.0030.04321.29
5.6.160.0070.08721.20
5.6.150.0000.05721.27
5.6.140.0030.04021.14
5.6.130.0070.04021.28
5.6.120.0070.07721.03
5.6.110.0030.04321.22
5.6.100.0070.06321.16
5.6.90.0030.04321.26
5.6.80.0000.04720.71
5.6.70.0000.04020.70
5.6.60.0100.03020.57
5.6.50.0070.03720.44
5.6.40.0030.03720.55
5.6.30.0100.03320.54
5.6.20.0070.03720.47
5.6.10.0000.03720.38
5.6.00.0130.06720.54
5.5.380.0100.08320.51
5.5.370.0030.04720.51
5.5.360.0200.07320.65
5.5.350.0030.05320.64
5.5.340.0100.04320.98
5.5.330.0000.05020.93
5.5.320.0070.03321.02
5.5.310.0030.04320.86
5.5.300.0030.04020.91
5.5.290.0130.06721.07
5.5.280.0070.04020.92
5.5.270.0100.03021.02
5.5.260.0000.05320.92
5.5.250.0130.02720.83
5.5.240.0030.05020.43
5.5.230.0100.05020.44
5.5.220.0030.04020.43
5.5.210.0070.03720.45
5.5.200.0030.06320.40
5.5.190.0070.04020.18
5.5.180.0070.03720.41
5.5.160.0070.05320.35
5.5.150.0000.04320.29
5.5.140.0070.06720.28
5.5.130.0100.07320.33
5.5.120.0100.04720.28
5.5.110.0030.08720.31
5.5.100.0130.08020.29
5.5.90.0100.07320.07
5.5.80.0170.06720.32
5.5.70.0030.07720.25
5.5.60.0070.07720.13
5.5.50.0070.06720.18
5.5.40.0070.05320.29
5.5.30.0070.07020.15
5.5.20.0030.04320.12
5.5.10.0100.07320.10
5.5.00.0030.06320.20
5.4.450.0030.04319.36
5.4.440.0100.03719.56
5.4.430.0030.04019.27
5.4.420.0000.08319.69
5.4.410.0070.04019.31
5.4.400.0100.03319.18
5.4.390.0070.03718.95
5.4.380.0070.03719.25
5.4.370.0030.05719.23
5.4.360.0070.05319.01
5.4.350.0030.04319.12
5.4.340.0100.03319.03
5.4.320.0100.07319.38
5.4.310.0000.04319.37
5.4.300.0030.03719.02
5.4.290.0070.08019.28
5.4.280.0170.07018.93
5.4.270.0070.07319.24
5.4.260.0030.07719.30
5.4.250.0070.08018.95
5.4.240.0000.05719.13
5.4.230.0070.08319.26
5.4.220.0070.07319.25
5.4.210.0000.08019.12
5.4.200.0100.06719.24
5.4.190.0170.07018.92
5.4.180.0130.06719.02
5.4.170.0070.04718.95
5.4.160.0070.07318.91
5.4.150.0070.07719.23
5.4.140.0130.06316.42
5.4.130.0000.06316.59
5.4.120.0100.06316.41
5.4.110.0070.04716.59
5.4.100.0030.08316.64
5.4.90.0170.05016.68
5.4.80.0070.07716.52
5.4.70.0000.07316.74
5.4.60.0070.06016.52
5.4.50.0030.06716.57
5.4.40.0100.04316.49
5.4.30.0100.05316.55
5.4.20.0070.07316.56
5.4.10.0130.07016.66
5.4.00.0070.07016.05
5.3.290.0070.03014.64
5.3.280.0170.06314.55
5.3.270.0070.07714.45
5.3.260.0030.07714.60
5.3.250.0030.08314.46
5.3.240.0100.07014.61
5.3.230.0100.04314.54
5.3.220.0100.07314.57
5.3.210.0070.05314.57
5.3.200.0030.03714.43
5.3.190.0030.05714.43
5.3.180.0100.06714.55
5.3.170.0070.05714.52
5.3.160.0070.06714.54
5.3.150.0170.06014.43
5.3.140.0100.07714.42
5.3.130.0070.05014.55
5.3.120.0000.05014.54
5.3.110.0030.06714.54
5.3.100.0030.05714.00
5.3.90.0030.07313.88
5.3.80.0100.07013.98
5.3.70.0130.03314.00
5.3.60.0130.07013.93
5.3.50.0070.05013.71
5.3.40.0130.07313.90
5.3.30.0100.07313.86
5.3.20.0070.08013.67
5.3.10.0130.05713.61
5.3.00.0070.07313.61
5.2.170.0100.06010.99
5.2.160.0130.03011.18
5.2.150.0070.06011.16
5.2.140.0130.03710.93
5.2.130.0100.04311.05
5.2.120.0070.05010.96
5.2.110.0070.06011.10
5.2.100.0070.05011.15
5.2.90.0000.05010.92
5.2.80.0000.05710.89
5.2.70.0070.04011.14
5.2.60.0000.05011.00
5.2.50.0030.06311.07
5.2.40.0000.05310.81
5.2.30.0100.05010.81
5.2.20.0030.06311.01
5.2.10.0100.05010.90
5.2.00.0100.05310.64
5.1.60.0070.04710.00
5.1.50.0070.0509.98
5.1.40.0030.0509.96
5.1.30.0070.04010.37
5.1.20.0000.06010.39
5.1.10.0100.0439.90
5.1.00.0030.03710.15
5.0.50.0070.0278.54
5.0.40.0000.0208.24
5.0.30.0030.0578.06
5.0.20.0030.0478.26
5.0.10.0030.0438.26
5.0.00.0070.0608.19
4.4.90.0030.0337.38
4.4.80.0000.0307.38
4.4.70.0030.0307.38
4.4.60.0000.0377.38
4.4.50.0030.0237.38
4.4.40.0030.0507.38
4.4.30.0030.0377.38
4.4.20.0030.0377.38
4.4.10.0030.0337.38
4.4.00.0000.0277.38
4.3.110.0000.0377.38
4.3.100.0030.0307.38
4.3.90.0000.0377.38
4.3.80.0100.0507.38
4.3.70.0030.0237.38
4.3.60.0070.0307.38
4.3.50.0030.0377.38
4.3.40.0000.0537.38
4.3.30.0030.0377.38
4.3.20.0000.0377.38
4.3.10.0000.0337.38
4.3.00.0000.0337.38

preferences:
45.14 ms | 401 KiB | 5 Q