3v4l.org

run code in 300+ PHP versions simultaneously
<?php const VALUE_FORMAT_RAW = "raw"; const VALUE_FORMAT_TAG_NAME_VALUE_ASSOC = "tagNameValueAssoc"; const VALUE_FORMAT_ARRAY = "array"; function formatArgumentValue(SimpleXMLElement $node, $options) { switch ($options["format"]) { // Associative array from each children of the target node that have the tag name as key and // the tag value as value case VALUE_FORMAT_TAG_NAME_VALUE_ASSOC: $assoc = []; // Recursively get the associative array for the node foreach ($node->children() as $nodePart) { if($nodePart->count() > 0) { $format = VALUE_FORMAT_TAG_NAME_VALUE_ASSOC; if (!empty($nodePart->attributes()->type) && $nodePart->attributes()->type == "array") { $format = VALUE_FORMAT_ARRAY; } $assoc[$nodePart->getName()] = $this->formatArgumentValue($nodePart, ["format" => $format]); } else { // If the value is already defined, we say that the value is an array and add the new value to it if(!empty($assoc[$nodePart->getName()])) { if(!is_array($assoc[$nodePart->getName()])) { $assoc[$nodePart->getName()] = [$assoc[$nodePart->getName()]]; } $assoc[$nodePart->getName()][] = $this->resolveValueString((string) $nodePart); } else { $assoc[$nodePart->getName()] = $this->resolveValueString((string) $nodePart); } } } $argumentValue = $assoc; break; case VALUE_FORMAT_ARRAY: $children = []; $i = 0; foreach($node->children() as $child) { // Get the path for the key $key = $i++; // Set the default key as a regular numbered autoincremented index // NOTE: Here a post-increment is done, the value copied to $key is $i BEFORE // it being incremented. The array will start at 0, even if the increment is done at // the beginning of the string. if(!empty($options['childrenKey'])) { $key = (string) $this->walkNodePath($options['childrenKey'], $child); } $children[$key] = $this->formatArgumentValue($child, ["format" => $options["childrenFormat"]]); } $argumentValue = $children; break; // Raw string value of the tag as value. Default. case VALUE_FORMAT_RAW: default: $argumentValue = $this->resolveValueString((string) $node); break; } return $argumentValue; } $xml = <<<EOL <config> <formatters> <fileformatter> <class>Monolog\Formatter\LineFormatter</class> <format>[%datetime%] %level_name%: %message%&#xA;</format> </fileformatter> <mongoformatter> <class>Bettr\Service\Log\Formatter\MongoDBFormatter</class> </mongoformatter> </formatters> <handlers> <filelog> <class>Monolog\Handler\StreamHandler</class> <level>DEBUG</level> <formatter>fileformatter</formatter> <processors>psr_processor</processors> <stream>../system/var/logs/debug.log</stream> </filelog> <mongolog> <class>Bettr\Service\Log\Handler\MongoServiceHandler</class> <level>ERROR</level> <formatter>mongoformatter</formatter> <mongoManager>{service:mongo}</mongoManager> <processors type="array">psr_processor</processors> <collection>logger</collection> </mongolog> </handlers> <processors> <psr_processor> <class>Monolog\Processor\PsrLogMessageProcessor</class> </psr_processor> </processors> <loggers> <bettr> <handlers type="array"> <handler>filelog</handler> <handler>mongolog</handler> </handlers> </bettr> </loggers> </config> EOL; $simpleXMLElement = new SimpleXMLElement($xml); var_dump(formatArgumentValue($simpleXMLElement, ["format" => VALUE_FORMAT_TAG_NAME_VALUE_ASSOC]));

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.0130.00618.68
8.3.50.0040.01118.23
8.3.40.0120.00619.23
8.3.30.0110.00419.09
8.3.20.0110.00419.27
8.3.10.0030.00622.15
8.3.00.0070.00323.86
8.2.180.0120.00318.68
8.2.170.0120.00322.96
8.2.160.0110.00319.79
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0040.00420.90
8.2.120.0000.00926.35
8.2.110.0050.00522.57
8.2.100.0040.00718.20
8.2.90.0000.00919.66
8.2.80.0030.00718.00
8.2.70.0050.00318.28
8.2.60.0000.00818.30
8.2.50.0040.00418.10
8.2.40.0030.00619.66
8.2.30.0000.00819.60
8.2.20.0040.00418.37
8.2.10.0050.00318.37
8.2.00.0100.00019.71
8.1.280.0120.00325.92
8.1.270.0040.00422.23
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0090.00022.67
8.1.230.0090.00319.33
8.1.220.0100.00018.15
8.1.210.0030.00518.77
8.1.200.0060.00317.73
8.1.190.0000.00917.60
8.1.180.0080.00018.10
8.1.170.0000.00819.27
8.1.160.0040.00419.08
8.1.150.0000.00819.23
8.1.140.0040.00417.89
8.1.130.0000.00719.30
8.1.120.0030.00617.79
8.1.110.0000.00717.78
8.1.100.0040.00417.65
8.1.90.0040.00417.64
8.1.80.0030.00617.64
8.1.70.0050.00317.67
8.1.60.0020.00517.86
8.1.50.0080.00017.70
8.1.40.0000.00817.81
8.1.30.0080.00018.01
8.1.20.0080.00417.93
8.1.10.0000.00917.80
8.1.00.0030.00517.81
8.0.300.0040.00418.77
8.0.290.0080.00017.13
8.0.280.0000.00718.78
8.0.270.0050.00217.45
8.0.260.0000.01117.44
8.0.250.0020.00517.36
8.0.240.0000.00817.38
8.0.230.0040.00417.35
8.0.220.0080.00017.15
8.0.210.0030.00317.28
8.0.200.0000.00717.20
8.0.190.0000.00717.37
8.0.180.0000.00817.37
8.0.170.0000.00917.30
8.0.160.0050.00317.10
8.0.150.0000.00917.12
8.0.140.0040.00417.13
8.0.130.0000.00613.62
8.0.120.0040.00417.13
8.0.110.0020.00517.26
8.0.100.0040.00417.29
8.0.90.0040.00417.31
8.0.80.0160.00317.21
8.0.70.0000.00717.33
8.0.60.0000.00917.37
8.0.50.0030.00517.20
8.0.30.0110.00817.39
8.0.20.0100.01217.40
8.0.10.0030.00617.37
8.0.00.0090.00917.07
7.4.330.0000.00715.55
7.4.320.0060.00016.90
7.4.300.0000.00716.88
7.4.290.0030.00316.80
7.4.280.0080.00316.70
7.4.270.0000.00716.81
7.4.260.0030.00316.73
7.4.250.0050.00316.77
7.4.240.0040.00416.92
7.4.230.0070.00016.97
7.4.220.0030.00616.71
7.4.210.0060.01116.86
7.4.200.0040.00316.61
7.4.160.0090.00716.82
7.4.140.0130.00517.86
7.4.130.0130.00916.85
7.4.120.0100.00916.88
7.4.110.0030.01316.97
7.4.100.0060.01116.84
7.4.90.0100.00716.64
7.4.80.0090.00919.39
7.4.70.0150.00916.93
7.4.60.0140.00316.70
7.4.50.0070.01016.77
7.4.40.0060.01216.76
7.4.00.0060.01115.08
7.3.330.0000.00513.48
7.3.320.0050.00013.48
7.3.310.0030.00316.59
7.3.300.0070.00016.54
7.3.290.0000.00816.48
7.3.280.0060.01016.52
7.3.260.0100.00916.71
7.3.240.0090.01016.76
7.3.230.0090.00916.60
7.3.210.0130.01016.63
7.3.200.0080.01116.69
7.3.190.0120.00816.64
7.3.180.0140.00716.66
7.3.170.0090.00916.59
7.3.160.0040.01316.68
7.3.120.0080.00914.99
7.3.110.0020.01414.95
7.3.100.0080.00814.81
7.3.90.0070.00915.03
7.3.80.0080.00915.03
7.3.70.0080.00514.93
7.3.60.0070.00515.04
7.3.50.0040.01015.02
7.3.40.0070.00814.94
7.3.30.0070.00815.04
7.3.20.0020.00916.74
7.3.10.0070.00516.67
7.3.00.0100.00216.61
7.2.330.0100.01017.02
7.2.320.0060.01217.08
7.2.310.0120.00617.00
7.2.300.0220.01917.11
7.2.290.0090.00916.95
7.2.250.0080.01015.30
7.2.240.0060.01415.29
7.2.230.0060.00715.19
7.2.220.0070.00815.34
7.2.210.0060.00815.40
7.2.200.0020.01215.16
7.2.190.0040.00915.19
7.2.180.0120.00415.28
7.2.170.0070.01015.19
7.2.160.0030.01015.25
7.2.150.0060.00616.98
7.2.140.0060.01016.76
7.2.130.0090.00617.14
7.2.120.0030.01017.17
7.2.110.0030.01116.98
7.2.100.0120.00316.94
7.2.90.0030.01217.37
7.2.80.0030.01016.90
7.2.70.0220.01116.00
7.2.60.0300.00516.20
7.2.50.0190.00716.05
7.2.40.0160.00915.88
7.2.30.0150.01016.25
7.2.20.0220.00416.17
7.2.10.0220.00715.84
7.2.00.0240.01416.05
7.1.330.0100.00515.96
7.1.320.0040.01015.94
7.1.310.0080.00515.84
7.1.300.0040.00815.86
7.1.290.0060.00715.89
7.1.280.0080.00415.87
7.1.270.0040.00715.91
7.1.260.0060.00715.96
7.1.250.0080.00415.87
7.1.240.0110.00416.08
7.1.230.0070.00416.13
7.1.220.0030.01415.88
7.1.210.0040.00715.95
7.1.200.0060.00815.91
7.1.190.0030.00716.03
7.1.180.0130.00315.61
7.1.170.0190.00514.94
7.1.160.0170.00814.97
7.1.150.0200.00715.03
7.1.140.0190.00714.97
7.1.130.0160.00614.88
7.1.120.0190.01215.01
7.1.110.0190.00414.85
7.1.100.0210.00514.77
7.1.90.0200.00814.88
7.1.80.0200.01015.05
7.1.70.0570.01114.99
7.1.60.0320.01723.98
7.1.50.0290.00824.04
7.1.40.0380.01923.84
7.1.30.0360.01123.80
7.1.20.0270.01623.89
7.1.10.0210.01114.90
7.1.00.0170.00614.90
7.0.330.0070.00715.50
7.0.320.0080.00415.54
7.0.310.0040.00415.48
7.0.300.0060.00315.47
7.0.290.0150.00015.50
7.0.280.0000.01315.39
7.0.270.0080.00015.46
7.0.260.0100.00315.27
7.0.250.0090.00015.43
7.0.240.0000.01215.45
7.0.230.0000.00915.56
7.0.220.0070.01015.64
7.0.210.0070.01015.56
7.0.200.0040.00815.43
7.0.190.0040.00715.43
7.0.180.0000.00915.49
7.0.170.0000.01215.39
7.0.160.0100.00715.28
7.0.150.0030.01315.35
7.0.140.0100.00015.45
7.0.130.0040.01115.55
7.0.120.0070.00715.41
7.0.110.0140.00015.69
7.0.100.0040.01115.59
7.0.90.0060.00615.69
7.0.80.0000.00915.57
7.0.70.0000.01115.44
7.0.60.0060.00615.54
7.0.50.0030.00915.50
7.0.40.0030.00613.32
7.0.30.0070.00713.60
7.0.20.0130.00013.68
7.0.10.0040.00813.63
7.0.00.0100.00313.67
5.6.400.0060.00914.63
5.6.390.0060.00314.29
5.6.380.0040.01114.16
5.6.370.0050.00514.22
5.6.360.0060.00614.62
5.6.350.0090.00614.48
5.6.340.0030.00914.30
5.6.330.0040.01114.71
5.6.320.0100.00314.64
5.6.310.0070.00714.50
5.6.300.0080.00614.35
5.6.290.0000.01214.32
5.6.280.0070.00614.47
5.6.270.0060.00314.48
5.6.260.0090.00614.51
5.6.250.0030.00614.43
5.6.240.0070.00714.54
5.6.230.0130.00314.52
5.6.220.0100.00314.62
5.6.210.0000.01314.26
5.6.200.0060.00314.89
5.6.190.0090.00014.34
5.6.180.0060.00914.50
5.6.170.0120.00314.69
5.6.160.0070.00714.53
5.6.150.0090.00614.40
5.6.140.0110.00014.54
5.6.130.0030.00614.48
5.6.120.0080.00414.28
5.6.110.0120.00314.75
5.6.100.0120.00314.27
5.6.90.0100.00314.45
5.6.80.0030.00914.32
5.6.70.0040.00814.50
5.6.60.0090.00614.48
5.6.50.0120.00014.44
5.6.40.0150.00014.23
5.6.30.0070.01114.75
5.6.20.0090.00614.63
5.6.10.0030.01314.48
5.6.00.0090.00614.71

preferences:
76.31 ms | 401 KiB | 5 Q