3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toXml(SimpleXMLElement $xml, array $data, $mainKey = null) { foreach ($data as $key => $value) { // if the key is an integer, it needs text with it to actually work. if (is_numeric($key)) { $key = $mainKey ? : "key_$key"; } if (is_array($value)) { $childXml = $xml->addChild($key); toXml($childXml, $value, substr($key, 0, -1)); } else { $xml->addChild($key, $value); } } return $xml; } // Pretty print Xml function formatXml($simpleXMLElement) { $xmlDocument = new DOMDocument('1.0'); $xmlDocument->preserveWhiteSpace = false; $xmlDocument->formatOutput = true; $xmlDocument->loadXML($simpleXMLElement->asXML()); return $xmlDocument->saveXML(); } $arr_albums = array(); $rows1 = array(array('Id' => 4)); $rows3 = array(array('Id' => 2, 'Name' => 'viktor_rood.png'), array('Id' => 5, 'Name' => 'viktor_geel.png'), array('Id' => 7, 'Name' => 'viktor_paars.png'), array('Id' => 8, 'Name' => 'viktor_aqua.png') ); foreach ($rows1 as $row1) { $arr_images = array(); foreach ($rows3 as $row3) { $image_array = array( 'Id' => $row3["Id"], 'Name' => $row3["Name"] ); $arr_images[] = $image_array; } $album_array = array( 'Id' => $row1["Id"], 'Images' => $arr_images ); $arr_albums[] = $album_array; } $xml = toXml(new SimpleXMLElement('<Albums/>'), $arr_albums, 'Album'); print formatXml($xml);

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.5.00.0180.00620.22
8.4.150.0030.00014.05
8.4.140.0120.00917.87
8.4.130.0080.01018.87
8.4.120.0130.00824.42
8.4.110.0100.01018.81
8.4.100.0110.01018.93
8.4.90.0100.00822.87
8.4.80.0060.00418.89
8.4.70.0150.00620.86
8.4.60.0110.00919.05
8.4.50.0040.00419.14
8.4.40.0080.00018.14
8.4.30.0030.00620.86
8.4.20.0060.01317.92
8.4.10.0000.00818.00
8.3.280.0140.00618.95
8.3.270.0120.00717.28
8.3.260.0130.00416.89
8.3.250.0120.00719.46
8.3.240.0120.00617.51
8.3.230.0060.00316.77
8.3.220.0100.00819.14
8.3.210.0120.00317.24
8.3.200.0100.00917.00
8.3.190.0050.00719.15
8.3.180.0130.00517.55
8.3.170.0110.00721.02
8.3.160.0110.00318.59
8.3.150.0160.00317.69
8.3.140.0070.00716.68
8.3.130.0000.00918.64
8.3.120.0000.00919.41
8.3.110.0160.00316.88
8.3.100.0090.00324.06
8.3.90.0060.00326.77
8.3.80.0060.00619.36
8.3.70.0070.01416.99
8.3.60.0130.01018.55
8.3.50.0070.01123.77
8.3.40.0090.00619.09
8.3.30.0120.00319.10
8.3.20.0080.00023.94
8.3.10.0000.00820.54
8.3.00.0040.00422.02
8.2.290.0110.00820.84
8.2.280.0080.00718.56
8.2.270.0070.01117.52
8.2.260.0030.00716.75
8.2.250.0150.00318.87
8.2.240.0060.00317.39
8.2.230.0060.00320.94
8.2.220.0030.00537.54
8.2.210.0080.00026.77
8.2.200.0060.00318.88
8.2.190.0110.00716.75
8.2.180.0140.00718.66
8.2.170.0090.00622.96
8.2.160.0030.01020.90
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0080.00020.04
8.2.110.0060.00321.38
8.2.100.0100.00618.16
8.2.90.0000.00818.53
8.2.80.0000.00820.86
8.2.70.0040.00418.18
8.2.60.0000.00818.47
8.2.50.0000.00818.10
8.2.40.0080.00319.49
8.2.30.0000.00719.55
8.2.20.0040.00418.41
8.2.10.0000.01319.62
8.2.00.0070.00019.59
8.1.330.0110.00722.27
8.1.320.0090.01116.39
8.1.310.0070.00316.70
8.1.300.0090.00918.93
8.1.290.0090.00030.84
8.1.280.0120.00325.92
8.1.270.0050.00222.57
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0060.00322.51
8.1.230.0080.00321.21
8.1.220.0080.00018.02
8.1.210.0000.00819.35
8.1.200.0000.00917.72
8.1.190.0040.00417.73
8.1.180.0000.00819.46
8.1.170.0090.00018.96
8.1.160.0050.00519.37
8.1.150.0040.00419.20
8.1.140.0040.00421.07
8.1.130.0000.00720.61
8.1.120.0040.00417.76
8.1.110.0050.00317.74
8.1.100.0030.00517.68
8.1.90.0000.00817.66
8.1.80.0040.00417.68
8.1.70.0050.00317.66
8.1.60.0040.00417.84
8.1.50.0090.00017.84
8.1.40.0000.00817.86
8.1.30.0030.00618.01
8.1.20.0040.00417.94
8.1.10.0040.00417.90
8.1.00.0000.00817.83
8.0.300.0040.00420.41
8.0.290.0040.00417.25
8.0.280.0030.00518.75
8.0.270.0000.00717.24
8.0.260.0000.00620.39
8.0.250.0050.00317.21
8.0.240.0000.00717.16
8.0.230.0030.00317.21
8.0.220.0070.00017.32
8.0.210.0000.00817.32
8.0.200.0030.00317.38
8.0.190.0060.00317.24
8.0.180.0000.00817.29
8.0.170.0030.00617.24
8.0.160.0040.00417.26
8.0.150.0030.00617.15
8.0.140.0100.00017.25
8.0.130.0060.00013.65
8.0.120.0000.00817.28
8.0.110.0070.00017.19
8.0.100.0000.00717.31
8.0.90.0000.00917.11
8.0.80.0010.01617.21
8.0.70.0000.00717.20
8.0.60.0040.00417.34
8.0.50.0070.00017.32
8.0.30.0040.01517.22
8.0.20.0120.00817.43
8.0.10.0060.00317.45
8.0.00.0090.00916.90
7.4.330.0000.00617.14
7.4.320.0000.00616.77
7.4.300.0040.00416.83
7.4.290.0030.00316.81
7.4.280.0080.00416.73
7.4.270.0080.00316.86
7.4.260.0030.00313.68
7.4.250.0000.00716.87
7.4.240.0050.00216.79
7.4.230.0070.00016.83
7.4.220.0030.00316.95
7.4.210.0080.01016.91
7.4.200.0000.00717.00
7.4.140.0120.00617.86
7.4.130.0110.00816.80
7.4.120.0040.01416.83
7.4.110.0120.00617.01
7.4.100.0070.01616.87
7.4.90.0050.01316.87
7.4.80.0060.01919.39
7.4.70.0170.00316.78
7.4.60.0100.00716.85
7.4.50.0040.00816.61
7.4.40.0080.00816.93
7.4.20.0060.01616.41
7.4.10.0100.00716.22
7.4.00.0150.00617.04
7.3.330.0000.00716.73
7.3.320.0040.00413.46
7.3.310.0040.00416.80
7.3.300.0030.00316.71
7.3.290.0030.00316.72
7.3.260.0170.00716.77
7.3.230.0120.00916.74
7.3.210.0030.01316.68
7.3.200.0070.01116.71
7.3.190.0070.01016.57
7.3.180.0060.01216.92
7.3.170.0100.00716.74
7.3.160.0110.00516.72
7.3.130.0040.01216.24
7.3.120.0110.01116.67
7.3.110.0080.00816.61
7.3.100.0030.01316.43
7.3.90.0070.01416.50
7.3.80.0160.00716.43
7.3.70.0100.00716.62
7.3.60.0070.01516.63
7.3.50.0070.01116.64
7.3.40.0130.00916.56
7.3.30.0030.01316.64
7.3.20.0130.01016.55
7.3.10.0110.00716.63
7.3.00.0140.00316.50
7.2.330.0030.01416.90
7.2.320.0090.00917.12
7.2.310.0170.00016.68
7.2.300.0030.01417.13
7.2.290.0030.01417.09
7.2.260.0130.00316.72
7.2.250.0110.01016.77
7.2.240.0060.01216.94
7.2.230.0030.01416.64
7.2.220.0060.01616.88
7.2.210.0030.01416.55
7.2.200.0060.01116.60
7.2.190.0190.00516.81
7.2.180.0060.01616.78
7.2.170.0040.01416.71
7.2.160.0130.00316.71
7.2.150.0280.00716.92
7.2.140.0160.00916.84
7.2.130.0090.00916.79
7.2.120.0060.01216.76
7.2.110.0130.00916.91
7.2.100.0100.00716.84
7.2.90.0070.01116.80
7.2.80.0100.01316.68
7.2.70.0090.01516.55
7.2.60.0140.00516.79
7.2.50.0120.00816.40
7.2.40.0050.01816.82
7.2.30.0080.01116.78
7.2.20.0130.01016.93
7.2.10.0060.01216.85
7.2.00.0170.00716.84

preferences:
31.1 ms | 403 KiB | 5 Q