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($inner)) { 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.0060.01317.00
8.3.50.0120.00917.80
8.3.40.0080.00818.95
8.3.30.0040.01119.09
8.3.20.0160.00319.16
8.3.10.0030.00620.75
8.3.00.0040.00419.48
8.2.180.0150.00625.92
8.2.170.0090.00919.17
8.2.160.0070.01022.96
8.2.150.0060.00324.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0030.00519.10
8.2.110.0090.00019.62
8.2.100.0060.00618.16
8.2.90.0060.00319.55
8.2.80.0040.00417.97
8.2.70.0030.00617.88
8.2.60.0000.00918.41
8.2.50.0060.00318.10
8.2.40.0050.00518.40
8.2.30.0000.01020.14
8.2.20.0060.00319.65
8.2.10.0000.00918.02
8.2.00.0030.00618.03
8.1.280.0150.00625.92
8.1.270.0080.00024.66
8.1.260.0130.01026.35
8.1.250.0090.00028.09
8.1.240.0060.00324.20
8.1.230.0110.00018.07
8.1.220.0050.00317.93
8.1.210.0060.00318.77
8.1.200.0060.00317.60
8.1.190.0050.00517.60
8.1.180.0000.00818.10
8.1.170.0080.00019.15
8.1.160.0030.00619.24
8.1.150.0040.00418.86
8.1.140.0060.00317.76
8.1.130.0060.00318.11
8.1.120.0030.00617.65
8.1.110.0030.00517.86
8.1.100.0000.00717.63
8.1.90.0070.00017.83
8.1.80.0040.00417.80
8.1.70.0030.00317.73
8.1.60.0090.00017.86
8.1.50.0040.00417.79
8.1.40.0020.00517.90
8.1.30.0040.00418.03
8.1.20.0030.00518.00
8.1.10.0030.00617.95
8.1.00.0030.00517.84
8.0.300.0000.00818.77
8.0.290.0000.00817.00
8.0.280.0030.00318.72
8.0.270.0000.00717.60
8.0.260.0040.00417.07
8.0.250.0000.00817.39
8.0.240.0050.00317.37
8.0.230.0030.00317.25
8.0.220.0000.00717.23
8.0.210.0030.00317.14
8.0.200.0030.00317.22
8.0.190.0000.00717.19
8.0.180.0040.00417.31
8.0.170.0000.00817.30
8.0.160.0000.00717.31
8.0.150.0040.00417.29
8.0.140.0040.00417.25
8.0.130.0030.00313.76
8.0.120.0020.00517.09
8.0.110.0070.00017.13
8.0.100.0000.00817.19
8.0.90.0040.00417.18
8.0.80.0030.01417.14
8.0.70.0040.00417.13
8.0.60.0000.00717.34
8.0.50.0050.00317.26
8.0.30.0090.00917.53
8.0.20.0060.01417.44
8.0.10.0000.00817.36
8.0.00.0080.01017.23
7.4.330.0000.00513.27
7.4.320.0030.00316.91
7.4.300.0000.00616.68
7.4.290.0040.00416.69
7.4.280.0040.00416.86
7.4.270.0040.00416.90
7.4.260.0000.00613.52
7.4.250.0030.00616.82
7.4.240.0000.00716.86
7.4.230.0050.00216.89
7.4.220.0150.00616.73
7.4.210.0030.01216.88
7.4.200.0040.00416.68
7.4.190.0000.00716.95
7.4.160.0070.01016.97
7.4.150.0140.01016.88
7.4.140.0070.01016.97
7.4.130.0090.00916.89
7.4.120.0120.00616.75
7.4.110.0130.00716.78
7.4.100.0070.01016.88
7.4.90.0110.00716.96
7.4.80.0030.01419.39
7.4.70.0040.01316.91
7.4.60.0100.01616.64
7.4.50.0020.00216.84
7.4.40.0110.00716.66
7.4.30.0070.01016.93
7.4.10.0100.01015.03
7.4.00.0060.01215.20
7.3.330.0030.00313.55
7.3.320.0030.00313.61
7.3.310.0000.00716.73
7.3.300.0000.00716.52
7.3.290.0040.01116.68
7.3.280.0060.01116.60
7.3.270.0110.00716.75
7.3.260.0070.01016.63
7.3.250.0090.00916.78
7.3.240.0030.01616.90
7.3.230.0120.00916.63
7.3.210.0030.01416.55
7.3.200.0040.01316.71
7.3.190.0120.00916.84
7.3.180.0090.00616.61
7.3.170.0130.00616.84
7.3.160.0000.02316.79
7.3.130.0100.01014.92
7.3.120.0090.00814.95
7.3.110.0070.00915.13
7.3.100.0050.01015.09
7.3.90.0060.00815.08
7.3.80.0060.00415.01
7.3.70.0040.01014.98
7.3.60.0070.00515.18
7.3.50.0080.00214.85
7.3.40.0070.00814.97
7.3.30.0080.00715.04
7.3.20.0080.00616.85
7.3.10.0050.00816.80
7.3.00.0080.00616.82
7.2.330.0090.00917.20
7.2.320.0140.00617.14
7.2.310.0080.01216.76
7.2.300.0040.01317.11
7.2.290.0140.01017.07
7.2.260.0040.01815.26
7.2.250.0080.01115.37
7.2.240.0090.00915.31
7.2.230.0050.00915.16
7.2.220.0120.00515.44
7.2.210.0080.00615.15
7.2.200.0020.00915.21
7.2.190.0060.00915.17
7.2.180.0060.00715.27
7.2.170.0040.01315.21
7.2.160.0000.01915.32
7.2.150.0110.00417.18
7.2.140.0000.01516.99
7.2.130.0070.00717.16
7.2.120.0060.00917.04
7.2.110.0050.00716.97
7.2.100.0060.00716.90
7.2.90.0060.00817.02
7.2.80.0070.00616.98
7.2.70.0020.01116.94
7.2.60.0040.00617.07
7.2.50.0100.00217.11
7.2.40.0040.01116.92
7.2.30.0000.01517.09
7.2.20.0020.01417.21
7.2.10.0100.00517.04
7.2.00.0050.01017.05
7.1.330.0050.00716.16
7.1.320.0050.01215.98
7.1.310.0020.01216.12
7.1.300.0000.01215.84
7.1.290.0080.00515.74
7.1.280.0090.00616.02
7.1.270.0030.01215.89
7.1.260.0120.00216.05
7.1.250.0030.01215.97
7.1.240.0140.00015.84
7.1.230.0050.01015.99
7.1.220.0080.00615.88
7.1.210.0060.00915.87
7.1.200.0040.01015.94
7.1.190.0070.00615.92
7.1.180.0080.00416.03
7.1.170.0050.00616.05
7.1.160.0070.00716.16
7.1.150.0030.00916.01
7.1.140.0060.00815.91
7.1.130.0020.01015.93
7.1.120.0060.00616.05
7.1.110.0050.00815.92
7.1.100.0080.00716.07
7.1.90.0030.01015.84
7.1.80.0040.00715.96
7.1.70.0040.00616.32
7.1.60.0100.00917.15
7.1.50.0090.01116.26
7.1.40.0090.00515.95
7.1.30.0030.01215.99
7.1.20.0090.00516.01
7.1.10.0070.00915.99
7.1.00.0050.02418.07
7.0.330.0000.01115.34
7.0.320.0070.00415.37
7.0.310.0060.00415.56
7.0.300.0020.01115.50
7.0.290.0040.00915.52
7.0.280.0030.01015.56
7.0.270.0100.00215.60
7.0.260.0090.00315.47
7.0.250.0080.00315.48
7.0.240.0090.00515.63
7.0.230.0050.00815.75
7.0.220.0050.00515.49
7.0.210.0030.00815.61
7.0.200.0050.00615.90
7.0.190.0070.00415.52
7.0.180.0100.00415.53
7.0.170.0080.00615.63
7.0.160.0040.00715.46
7.0.150.0020.01215.66
7.0.140.0070.02917.88
7.0.130.0070.00315.57
7.0.120.0070.02617.77
7.0.110.0030.01015.51
7.0.100.0090.00315.57
7.0.90.0060.00915.55
7.0.80.0030.01015.61
7.0.70.0030.00815.54
7.0.60.0070.03417.03
7.0.50.0070.02316.46
7.0.40.0030.03415.05
7.0.30.0030.02114.98
7.0.20.0090.03014.98
7.0.10.0050.02015.05
7.0.00.0100.01914.97
5.6.400.0060.00614.71
5.6.390.0000.00814.71
5.6.380.0120.00214.37
5.6.370.0020.01214.55
5.6.360.0050.00814.68
5.6.350.0010.01014.59
5.6.340.0020.01214.43
5.6.330.0050.01014.78
5.6.320.0020.00914.71
5.6.310.0050.00514.68
5.6.300.0000.01514.68
5.6.290.0050.01014.82
5.6.280.0080.02816.85
5.6.270.0060.00714.65
5.6.260.0040.00714.78
5.6.250.0050.00814.52
5.6.240.0020.01114.60
5.6.230.0040.00914.73
5.6.220.0020.01214.82
5.6.210.0070.03316.56
5.6.200.0090.02515.84
5.6.190.0050.03115.83
5.6.180.0100.01815.89
5.6.170.0110.02815.77
5.6.160.0020.03015.79
5.6.150.0060.02115.93
5.6.140.0040.03816.07
5.6.130.0060.03115.82
5.6.120.0040.03315.80
5.6.110.0060.02115.94
5.6.100.0050.01715.87
5.6.90.0080.01715.79
5.6.80.0040.01715.67
5.6.70.0080.01315.63
5.6.60.0050.01815.60
5.6.50.0040.01815.69
5.6.40.0020.02115.48
5.6.30.0050.01415.55
5.6.20.0040.01915.52
5.6.10.0050.01915.52
5.6.00.0050.01615.59
5.5.380.0020.00913.71
5.5.370.0050.00713.62
5.5.360.0050.00513.78
5.5.350.0060.02816.02
5.5.340.0070.03315.18
5.5.330.0030.03315.06
5.5.320.0050.03315.14
5.5.310.0080.03015.16
5.5.300.0030.02615.20
5.5.290.0050.03215.18
5.5.280.0040.01715.19
5.5.270.0040.02015.14
5.5.260.0040.02015.18
5.5.250.0060.01515.02
5.5.240.0070.01514.92
5.5.230.0010.02114.98
5.5.220.0050.01514.93
5.5.210.0070.01314.87
5.5.200.0030.01714.98
5.5.190.0050.01614.79
5.5.180.0060.01514.87
5.5.170.0070.00714.38
5.5.160.0030.01614.96
5.5.150.0070.01614.87
5.5.140.0050.01515.02
5.5.130.0030.01714.86
5.5.120.0030.01915.00
5.5.110.0050.01714.94
5.5.100.0040.01814.96
5.5.90.0050.01514.74
5.5.80.0050.01614.87
5.5.70.0020.02014.86
5.5.60.0050.01614.93
5.5.50.0020.02014.80
5.5.40.0050.02314.83
5.5.30.0070.01714.96
5.5.20.0070.02214.90
5.5.10.0040.01914.92
5.5.00.0040.03014.90
5.4.450.0070.02714.49
5.4.440.0020.02714.51
5.4.430.0060.01514.54
5.4.420.0040.01814.54
5.4.410.0040.01614.51
5.4.400.0050.01714.35
5.4.390.0090.01314.33
5.4.380.0060.01614.40
5.4.370.0050.01614.44
5.4.360.0050.01814.42
5.4.350.0030.02014.50
5.4.340.0050.01714.43
5.4.330.0040.00712.07
5.4.320.0040.01714.38
5.4.310.0060.01514.41
5.4.300.0010.01914.39
5.4.290.0040.01614.40
5.4.280.0060.01614.42
5.4.270.0030.01714.36
5.4.260.0050.01814.37
5.4.250.0060.01514.39
5.4.240.0090.01214.39
5.4.230.0040.01614.37
5.4.220.0050.01814.37
5.4.210.0100.01114.43
5.4.200.0050.01914.49
5.4.190.0060.01814.32
5.4.180.0050.03014.37
5.4.170.0110.02514.40
5.4.160.0060.01914.38
5.4.150.0050.02914.43
5.4.140.0030.03113.54
5.4.130.0080.02613.57
5.4.120.0120.02213.60
5.4.110.0090.01913.56
5.4.100.0060.01813.62
5.4.90.0080.02213.56
5.4.80.0080.02413.48
5.4.70.0070.02913.57
5.4.60.0060.02413.67
5.4.50.0070.02013.50
5.4.40.0070.02713.53
5.4.30.0080.02113.57
5.4.20.0060.01913.51
5.4.10.0060.01813.57
5.4.00.0080.02213.45
5.3.290.0070.01412.51
5.3.280.0050.01612.49
5.3.270.0080.02512.51
5.3.260.0080.02812.53
5.3.250.0030.02912.43
5.3.240.0030.02712.52
5.3.230.0060.02812.45
5.3.220.0070.02612.50
5.3.210.0040.02112.46
5.3.200.0080.02612.49
5.3.190.0070.02412.49
5.3.180.0050.02512.55
5.3.170.0070.02212.49
5.3.160.0080.02212.56
5.3.150.0080.02512.47
5.3.140.0040.01912.55
5.3.130.0040.03012.50
5.3.120.0020.03312.42
5.3.110.0050.02412.42
5.3.100.0060.02112.24
5.3.90.0090.02412.35
5.3.80.0070.02712.29
5.3.70.0060.01812.27
5.3.60.0040.02312.32
5.3.50.0050.03012.26
5.3.40.0080.02612.29
5.3.30.0040.01812.28
5.3.20.0050.01512.11
5.3.10.0080.02112.16
5.3.00.0050.02312.19
5.2.170.0080.02711.96
5.2.160.0090.01811.92
5.2.150.0030.02411.94
5.2.140.0060.03111.96
5.2.130.0060.03211.95
5.2.120.0050.03011.91
5.2.110.0130.02811.83
5.2.100.0060.03512.01
5.2.90.0070.03211.92
5.2.80.0040.02711.92
5.2.70.0040.02511.91
5.2.60.0080.02011.90
5.2.50.0090.03211.79
5.2.40.0080.02811.88
5.2.30.0090.02711.87
5.2.20.0030.02111.86
5.2.10.0080.03311.83
5.2.00.0040.02911.68
5.1.60.0080.01311.38
5.1.50.0030.02811.46
5.1.40.0020.02711.41
5.1.30.0070.03011.63
5.1.20.0040.02111.52
5.1.10.0070.02911.40
5.1.00.0080.01411.42
5.0.50.0020.02810.71
5.0.40.0020.02410.62
5.0.30.0040.03310.49
5.0.20.0040.02110.53
5.0.10.0030.02010.58
5.0.00.0020.01810.45
4.4.90.0070.01210.45
4.4.80.0020.02110.45
4.4.70.0040.01610.45
4.4.60.0020.01610.45
4.4.50.0030.01210.45
4.4.40.0060.02710.45
4.4.30.0030.01510.45
4.4.20.0030.01810.45
4.4.10.0030.01110.45
4.4.00.0040.02310.45
4.3.110.0020.01210.45
4.3.100.0020.01710.45
4.3.90.0040.01910.45
4.3.80.0020.02810.45
4.3.70.0030.01310.45
4.3.60.0060.00810.45
4.3.50.0050.02010.45
4.3.40.0020.01510.45
4.3.30.0070.01510.45
4.3.20.0020.02010.45
4.3.10.0030.02010.45
4.3.00.0050.01810.45

preferences:
46.98 ms | 401 KiB | 5 Q