3v4l.org

run code in 300+ PHP versions simultaneously
<?php function xml2array($contents, $get_attributes = 1, $priority = 'tag') { if (!$contents) { return array(); } if (!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if (!$xml_values) { return;//Hmm... } //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array foreach ($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if (isset($value)) { if ($priority == 'tag') { $result = $value; } else { $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } } //Set the attributes too. if (isset($attributes) and $get_attributes) { foreach ($attributes as $attr => $val) { if ($priority == 'tag') { $attributes_data[$attr] = $val; } else { $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } } //See tag status and do the needed. if ($type == "open") {//The starting of the tag '<tag>' $parent[$level-1] = &$current; if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if ($attributes_data) { $current[$tag. '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if (isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif ($type == "complete") { //Tags that ends in 1 line '<tag />' //See if the key is already taken. if (!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if ($priority == 'tag' and $attributes_data) { $current[$tag. '_attr'] = $attributes_data; } } else { //If taken, put all things inside a list(array) if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if ($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if ($priority == 'tag' and $get_attributes) { if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if ($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif ($type == 'close') { //End of tag '</tag>' $current = &$parent[$level-1]; } } return($xml_array); } $response = '<?xml version="1.0" encoding="utf-8"?> <returnMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.doublepositive.com/"> <ErrorName>Success</ErrorName> <ErrorDescription>Approved – Assigned to Order</ErrorDescription> <LeadID>260554022</LeadID> <ClientAvailable>true</ClientAvailable> <ClientName>Post University</ClientName> <PrimaryNumber>8884051175</PrimaryNumber> <BackupNumber /> </returnMessage>'; $data = xml2array($response); var_dump($data);

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.01418.43
8.3.50.0120.00722.05
8.3.40.0040.01119.09
8.3.30.0120.00919.29
8.3.20.0000.00820.45
8.3.10.0080.00022.01
8.3.00.0050.00319.45
8.2.180.0090.00616.75
8.2.170.0070.00722.96
8.2.160.0070.00722.16
8.2.150.0090.00024.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0090.00019.89
8.2.110.0100.00020.75
8.2.100.0120.00018.03
8.2.90.0040.00419.61
8.2.80.0060.00318.00
8.2.70.0080.00017.75
8.2.60.0050.00318.29
8.2.50.0040.00418.07
8.2.40.0060.00320.20
8.2.30.0000.00718.33
8.2.20.0000.00817.92
8.2.10.0000.00818.46
8.2.00.0050.00317.95
8.1.280.0140.00425.92
8.1.270.0090.00019.22
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00622.25
8.1.230.0080.00322.48
8.1.220.0040.00417.79
8.1.210.0040.00418.77
8.1.200.0080.00617.48
8.1.190.0040.00417.47
8.1.180.0060.00318.10
8.1.170.0060.00318.96
8.1.160.0050.00222.29
8.1.150.0000.00719.17
8.1.140.0000.00817.61
8.1.130.0030.00318.04
8.1.120.0000.00717.68
8.1.110.0040.00417.69
8.1.100.0000.00717.60
8.1.90.0040.00417.56
8.1.80.0080.00017.73
8.1.70.0050.00217.75
8.1.60.0040.00417.79
8.1.50.0040.00417.72
8.1.40.0040.00417.85
8.1.30.0000.00817.91
8.1.20.0040.00417.90
8.1.10.0040.00417.66
8.1.00.0040.00417.74
8.0.300.0000.00718.77
8.0.290.0080.00016.88
8.0.280.0000.00718.57
8.0.270.0000.00717.47
8.0.260.0040.00417.43
8.0.250.0030.00317.05
8.0.240.0000.00717.31
8.0.230.0070.00017.09
8.0.220.0040.00417.14
8.0.210.0000.00717.00
8.0.200.0040.00417.16
8.0.190.0040.00417.23
8.0.180.0080.00017.18
8.0.170.0060.00317.00
8.0.160.0000.00717.11
8.0.150.0030.00517.11
8.0.140.0060.00317.08
8.0.130.0000.00613.48
8.0.120.0040.00417.21
8.0.110.0000.00817.25
8.0.100.0000.00717.03
8.0.90.0060.00317.03
8.0.80.0090.01217.08
8.0.70.0040.00417.10
8.0.60.0080.00017.13
8.0.50.0040.00417.13
8.0.30.0090.01317.49
8.0.20.0100.01217.57
8.0.10.0040.00417.23
8.0.00.0140.00517.05
7.4.330.0050.00015.30
7.4.320.0030.00316.82
7.4.300.0030.00316.72
7.4.290.0030.00516.77
7.4.280.0030.00616.71
7.4.270.0040.00416.87
7.4.260.0030.00716.87
7.4.250.0000.00816.76
7.4.240.0050.00216.81
7.4.230.0040.00416.71
7.4.220.0140.00416.80
7.4.210.0030.01216.73
7.4.200.0030.00516.98
7.4.160.0090.00916.62
7.4.150.0070.01117.40
7.4.140.0070.01517.86
7.4.130.0070.01016.83
7.4.120.0060.01316.73
7.4.110.0130.00916.84
7.4.100.0090.00916.50
7.4.90.0090.00916.62
7.4.80.0100.01019.39
7.4.70.0160.00316.74
7.4.60.0070.01816.72
7.4.50.0040.00416.73
7.4.40.0070.01016.55
7.4.30.0090.01216.77
7.4.00.0080.00815.13
7.3.330.0000.00813.64
7.3.320.0030.00313.48
7.3.310.0000.00716.60
7.3.300.0030.00316.44
7.3.290.0060.01116.63
7.3.280.0080.01016.61
7.3.270.0140.01417.40
7.3.260.0150.00416.81
7.3.250.0110.00616.79
7.3.240.0060.01216.81
7.3.230.0070.01016.58
7.3.210.0150.00316.57
7.3.200.0120.00619.39
7.3.190.0110.00716.87
7.3.180.0100.00616.48
7.3.170.0140.00716.81
7.3.160.0080.00816.59
7.2.330.0110.00716.95
7.2.320.0060.01217.05
7.2.310.0210.00316.92
7.2.300.0090.00916.74
7.2.290.0030.01517.00
7.2.00.0030.01019.68
7.1.100.0040.00818.01
7.1.70.0000.00816.96
7.1.60.0070.01719.46
7.1.50.0090.01217.05
7.1.00.0030.07322.55
7.0.200.0070.00317.00
7.0.140.0030.04322.18
7.0.60.0170.07019.91
7.0.50.0030.06018.09
7.0.40.0100.04020.43
7.0.30.0470.07720.32
7.0.20.0300.08020.31
7.0.10.0030.08720.29
7.0.00.0100.08720.38
5.6.280.0100.06721.01
5.6.210.0070.06020.94
5.6.200.0100.08318.26
5.6.190.0000.07720.75
5.6.180.0270.05320.54
5.6.170.0300.08720.64
5.6.160.0030.04020.59
5.6.150.0200.05318.28
5.6.140.0070.04018.22
5.6.130.0030.04318.35
5.6.120.0000.04321.22
5.6.110.0130.05721.17
5.6.100.0030.04721.27
5.6.90.0130.07721.04
5.6.80.0230.06720.63
5.5.350.4270.04320.49
5.5.340.0030.07718.20
5.5.330.0070.08020.38
5.5.320.2300.04320.41
5.5.310.0330.05020.38
5.5.300.0030.04718.13
5.5.290.0170.06718.05
5.5.280.0130.04321.06
5.5.270.0100.07720.79
5.5.260.0030.09320.91
5.5.250.0100.06720.59
5.5.240.0100.07720.49
5.4.450.0670.07319.39
5.4.440.0870.07019.78
5.4.430.0070.06719.46
5.4.420.0270.03719.68
5.4.410.0170.05019.53
5.4.400.0100.05719.12
5.4.390.0270.05318.70
5.4.380.0170.06018.86
5.4.370.0270.05018.55
5.4.360.0230.05018.71
5.4.350.0270.04718.72
5.4.340.0230.05018.68
5.4.320.0300.04718.67
5.4.310.0200.06018.83
5.4.300.0130.05718.77
5.4.290.0270.04718.52
5.4.280.0200.05018.78
5.4.270.0170.05718.78
5.4.260.0200.05018.68
5.4.250.0300.04318.70
5.4.240.0130.06318.88
5.4.230.0300.04718.60
5.4.220.0200.05718.83
5.4.210.0230.05318.77
5.4.200.0200.05016.79
5.4.190.0170.05318.80
5.4.180.0200.05718.65
5.4.170.0230.05318.61
5.4.160.0270.04718.71
5.4.150.0370.04018.78
5.4.140.0170.06016.37
5.4.130.0330.05016.43
5.4.120.0200.05016.37
5.4.110.0230.04316.36
5.4.100.0270.06716.52
5.4.90.0170.05316.48
5.4.80.0200.05016.35
5.4.70.0200.05316.28
5.4.60.0170.05316.31
5.4.50.0230.05716.43
5.4.40.0200.05716.49
5.4.30.0230.04716.41
5.4.20.0270.04716.27
5.4.10.0200.05316.25
5.4.00.0200.05715.89
5.3.290.0170.05714.77
5.3.280.0100.06014.70
5.3.270.0130.05714.88
5.3.260.0270.04714.75
5.3.250.0100.06014.98
5.3.240.0200.06314.78
5.3.230.0230.05014.82
5.3.220.0200.07314.80
5.3.210.0130.06014.74
5.3.200.0200.05314.74
5.3.190.0200.05014.97
5.3.180.0230.04714.86
5.3.170.0270.04314.85
5.3.160.0130.05714.68
5.3.150.0170.05314.68
5.3.140.0270.04314.78
5.3.130.0170.06014.82
5.3.120.0270.04714.96
5.3.110.0130.06014.93
5.3.100.0130.06314.39
5.3.90.0330.04014.24
5.3.80.0130.06014.18
5.3.70.0330.03714.36
5.3.60.0170.05314.35
5.3.50.0200.05014.05
5.3.40.0170.05714.35
5.3.30.0170.05714.32
5.3.20.0230.04713.84
5.3.10.0200.05013.96
5.3.00.0070.06713.94
5.2.170.0130.04711.43
5.2.160.0230.03311.29
5.2.150.0200.04011.46
5.2.140.0200.04311.45
5.2.130.0100.05311.34
5.2.120.0130.04311.42
5.2.110.0130.04311.16
5.2.100.0170.04011.25
5.2.90.0170.04011.50
5.2.80.0070.05311.45
5.2.70.0170.04711.37
5.2.60.0100.04711.23
5.2.50.0170.04311.12
5.2.40.0170.04011.32
5.2.30.0130.04311.20
5.2.20.0130.04311.27
5.2.10.0170.04011.08
5.2.00.0070.04710.89
5.1.60.0130.04010.38
5.1.50.0100.04010.31
5.1.40.0130.03710.28
5.1.30.0200.03010.69
5.1.20.0170.04010.66
5.1.10.0170.03310.26
5.1.00.0170.03310.17
5.0.50.0070.0338.74
5.0.40.0130.0238.83
5.0.30.0100.0408.52
5.0.20.0200.0208.39
5.0.10.0070.0438.47
5.0.00.0100.0408.34
4.4.90.0070.0237.56
4.4.80.0070.0237.56
4.4.70.0100.0207.56
4.4.60.0130.0177.56
4.4.50.0100.0207.56
4.4.40.0030.0437.56
4.4.30.0100.0207.56
4.4.20.0070.0237.56
4.4.10.0100.0207.56
4.4.00.0070.0377.56
4.3.110.0130.0207.56
4.3.100.0100.0237.56
4.3.90.0100.0237.56
4.3.80.0100.0377.56
4.3.70.0100.0207.56
4.3.60.0100.0177.56
4.3.50.0070.0237.56
4.3.40.0030.0377.56
4.3.30.0000.0277.56
4.3.20.0100.0237.56
4.3.10.0030.0237.56
4.3.00.0130.0238.72

preferences:
42.46 ms | 401 KiB | 5 Q