3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "Football / Germany / 1.Liga Football / Germany / 1.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / England / 1.Liga Football / England / 1.Liga Football / England / 2.Liga Football / England / 2.Liga Football / England / 3.Liga Hockey / Germany / 1.Liga Hockey / Germany / 1.Liga Hockey / Germany / 2.Liga Fechten / Meisterschaft Fechten / Meisterschaft Fechten / Weltmeister"; class ArrayStacker { protected $_depthArray; protected function _saveDepthKey($key, $depth) { if(!isset($this->_depthArray[$depth])) { $this->_depthArray[$depth] = array(); } if(!in_array($key, $this->_depthArray[$depth])) { $this->_depthArray[$depth][] = $key; return true; } return false; } public function stackArray($string) { $array = $this->_splitString($string); $stackedArray = array(); foreach($array as $row) { $stackedArray = array_merge_recursive($stackedArray, $this->_stack($row)); } return $stackedArray; } /** * Split the whole string into a big array * * @param string $string * @return array */ protected function _splitString($string) { $lines = explode("\n", $string); $i = 0; $array = array(); foreach($lines as $line) { $values = explode(' / ', $line); foreach($values as $v => $value) { $values[$v] = trim($value); // make sure we got no whitespaces } $array[$i] = $values; $i++; } return $array; } /** * Build a stacked array * * @param array $array unstacked array * @return stacked array */ protected function _stack($array) { $stackedArray = array(); $key = array_shift($array); $depth = count($array); // save key to find duplicated if(!$this->_saveDepthKey($key, $depth)) return null; if($depth == 1) { $stackedArray[$key] = $array[0]; // that's a single value } else { $stackedArray[$key] = $this->_stack($array); } return $stackedArray; } } $arrayStacker = new ArrayStacker(); var_dump($arrayStacker->stackArray($string));

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.0140.00718.56
8.3.50.0060.00921.94
8.3.40.0090.00918.96
8.3.30.0070.00719.21
8.3.20.0050.00320.34
8.3.10.0060.00322.28
8.3.00.0040.00422.46
8.2.180.0080.00816.48
8.2.170.0070.00722.96
8.2.160.0030.01020.89
8.2.150.0000.00824.18
8.2.140.0060.00324.66
8.2.130.0070.00726.16
8.2.120.0030.00517.75
8.2.110.0040.00422.13
8.2.100.0110.00019.76
8.2.90.0030.00519.30
8.2.80.0050.00317.97
8.2.70.0030.00617.63
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0050.00318.16
8.2.30.0000.00818.21
8.2.20.0040.00417.87
8.2.10.0000.00917.88
8.2.00.0040.00417.88
8.1.280.0000.01525.92
8.1.270.0040.00421.89
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0030.00623.79
8.1.230.0000.01119.16
8.1.220.0060.00317.74
8.1.210.0090.00018.77
8.1.200.0060.00617.35
8.1.190.0040.00417.30
8.1.180.0080.00018.84
8.1.170.0040.00418.57
8.1.160.0000.00722.04
8.1.150.0040.00418.72
8.1.140.0040.00417.44
8.1.130.0040.00417.76
8.1.120.0050.00217.50
8.1.110.0050.00317.46
8.1.100.0040.00417.48
8.1.90.0040.00417.49
8.1.80.0050.00217.38
8.1.70.0000.00717.45
8.1.60.0040.00417.59
8.1.50.0070.00017.43
8.1.40.0030.00617.55
8.1.30.0030.00517.66
8.1.20.0000.00817.59
8.1.10.0000.00817.64
8.1.00.0030.00717.49
8.0.300.0080.00018.77
8.0.290.0070.00017.18
8.0.280.0000.00718.40
8.0.270.0030.00317.28
8.0.260.0030.00316.84
8.0.250.0000.00717.02
8.0.240.0000.00816.95
8.0.230.0030.00616.92
8.0.220.0070.00017.02
8.0.210.0000.00816.91
8.0.200.0030.00317.07
8.0.190.0040.00416.94
8.0.180.0050.00216.93
8.0.170.0030.00516.87
8.0.160.0040.00417.03
8.0.150.0000.00716.99
8.0.140.0040.00416.97
8.0.130.0000.00613.37
8.0.120.0080.00016.86
8.0.110.0040.00416.91
8.0.100.0050.00216.91
8.0.90.0000.00716.93
8.0.80.0100.01016.89
8.0.70.0080.00016.81
8.0.60.0040.00416.88
8.0.50.0070.00016.83
8.0.30.0070.01117.14
8.0.20.0070.01217.42
8.0.10.0040.00417.14
8.0.00.0110.00816.79
7.4.330.0030.00315.00
7.4.320.0060.00016.54
7.4.300.0000.00616.46
7.4.290.0030.00316.62
7.4.280.0090.00016.49
7.4.270.0000.00816.52
7.4.260.0030.00316.49
7.4.250.0040.00416.45
7.4.240.0000.00816.46
7.4.230.0000.00816.41
7.4.220.0110.00516.54
7.4.210.0070.00816.59
7.4.200.0000.00716.50
7.4.190.0000.00716.66
7.4.160.0100.00716.57
7.4.150.0040.02117.40
7.4.140.0100.01217.86
7.4.130.0100.01016.69
7.4.120.0080.01016.60
7.4.110.0030.01416.81
7.4.100.0080.00916.46
7.4.90.0100.00716.57
7.4.80.0040.01919.39
7.4.70.0140.00416.66
7.4.60.0060.01116.47
7.4.50.0030.00316.66
7.4.40.0110.00722.77
7.4.30.0090.01216.58
7.4.00.0040.01115.07
7.3.330.0050.00013.42
7.3.320.0000.00513.46
7.3.310.0020.00516.34
7.3.300.0070.00016.36
7.3.290.0090.01316.43
7.3.280.0060.01216.39
7.3.270.0140.00317.40
7.3.260.0090.00916.67
7.3.250.0110.00716.54
7.3.240.0120.00616.59
7.3.230.0100.00616.73
7.3.210.0110.00716.70
7.3.200.0160.00019.39
7.3.190.0100.00716.60
7.3.180.0100.00716.55
7.3.170.0150.00816.41
7.3.160.0140.00516.54
7.3.120.0030.01014.93
7.2.330.0090.01516.89
7.2.320.0100.00616.76
7.2.310.0080.00916.51
7.2.300.0100.01016.61
7.2.290.0070.01516.86
7.2.60.0030.01016.62
7.2.00.0000.01119.61
7.1.200.0060.00615.53
7.1.100.0060.00318.32
7.1.70.0050.00216.92
7.1.60.0040.01519.82
7.1.50.0060.01616.98
7.1.00.0100.06722.50
7.0.200.0020.00516.82
7.0.140.0070.07022.18
7.0.100.0170.07020.00
7.0.90.0270.07719.98
7.0.80.0070.03720.16
7.0.70.0100.07320.05
7.0.60.0130.03320.09
7.0.50.0030.04320.35
7.0.40.0070.04020.18
7.0.30.0070.04020.13
7.0.20.0030.04320.13
7.0.10.0070.03020.05
7.0.00.0100.03720.09
5.6.280.0070.07021.12
5.6.250.0130.08020.79
5.6.240.0070.05720.59
5.6.230.0130.07720.62
5.6.220.0070.04320.60
5.6.210.0070.06020.60
5.6.200.0070.04021.09
5.6.190.0030.04321.19
5.6.180.0070.04021.15
5.6.170.0070.04021.07
5.6.160.0070.03721.07
5.6.150.0030.03321.03
5.6.140.0070.03321.09
5.6.130.0030.04021.07
5.6.120.0000.04321.08
5.6.110.0030.03721.02
5.6.100.0000.06721.13
5.6.90.0100.03021.05
5.6.80.0030.03320.44
5.6.70.0100.04020.41
5.6.60.0100.03320.40
5.6.50.0070.04320.33
5.6.40.0100.04020.50
5.6.30.0070.04020.47
5.6.20.0100.03720.45
5.6.10.0170.04020.45
5.6.00.0000.03720.43
5.5.380.0000.05020.41
5.5.370.0130.05720.44
5.5.360.0100.03320.50
5.5.350.0000.07720.49
5.5.340.0100.03720.65
5.5.330.0100.03720.87
5.5.320.0070.04020.75
5.5.310.0070.04720.95
5.5.300.0030.04720.91
5.5.290.0030.03720.65
5.5.280.0070.03020.88
5.5.270.0100.04020.84
5.5.260.0030.04020.78
5.5.250.0000.03720.75
5.5.240.0070.03720.24
5.5.230.0030.03320.14
5.5.220.0200.03020.17
5.5.210.0030.04320.29
5.5.200.0030.04320.20
5.5.190.0070.03720.29
5.5.180.0100.03320.10
5.5.160.0100.03020.29
5.5.150.0000.08320.27
5.5.140.0070.08320.18
5.5.130.0070.06020.14
5.5.120.0100.04020.12
5.5.110.0030.07320.14
5.5.100.0270.05719.99
5.5.90.0100.05019.99
5.5.80.0100.07720.02
5.5.70.0070.08720.05
5.5.60.0030.08020.15
5.5.50.0130.07020.17
5.5.40.0130.06720.04
5.5.30.0070.07720.07
5.5.20.0100.07320.07
5.5.10.0030.07720.05
5.5.00.0030.04319.96
5.4.450.0030.03719.35
5.4.440.0030.04019.36
5.4.430.0070.03719.38
5.4.420.0030.03719.36
5.4.410.0030.03019.24
5.4.400.0000.03319.14
5.4.390.0100.05018.87
5.4.380.0030.03319.13
5.4.370.0030.03319.14
5.4.360.0000.04019.15
5.4.350.0000.03319.05
5.4.340.0030.03719.13
5.4.320.0030.04019.04
5.4.310.0000.04018.85
5.4.300.0030.07318.88
5.4.290.0030.08319.04
5.4.280.0000.08719.16
5.4.270.0170.06719.04
5.4.260.0030.08019.04
5.4.250.0130.07319.09
5.4.240.0030.07319.23
5.4.230.0030.04319.13
5.4.220.0030.07719.13
5.4.210.0030.08019.02
5.4.200.0030.05719.16
5.4.190.0030.04719.11
5.4.180.0100.07019.04
5.4.170.0070.07718.94
5.4.160.0030.04318.88
5.4.150.0100.07319.03
5.4.140.0100.04716.46
5.4.130.0030.07016.36
5.4.120.0070.06016.47
5.4.110.0170.05716.52
5.4.100.0100.07316.52
5.4.90.0070.07316.39
5.4.80.0070.07316.53
5.4.70.0070.07016.33
5.4.60.0170.05016.46
5.4.50.0070.04016.46
5.4.40.0030.06016.39
5.4.30.0100.03316.41
5.4.20.0030.06016.31
5.4.10.0070.05716.34
5.4.00.0100.03315.70
5.3.290.0030.04014.75
5.3.280.0130.03314.55
5.3.270.0170.07014.65
5.3.260.0100.03314.56
5.3.250.0100.06314.55
5.3.240.0030.07314.70
5.3.230.0030.04314.62
5.3.220.0070.06314.73
5.3.210.0030.04714.73
5.3.200.0100.04014.57
5.3.190.0170.06314.66
5.3.180.0100.03714.57
5.3.170.0030.04014.57
5.3.160.0100.04014.59
5.3.150.0030.08314.52
5.3.140.0130.06714.64
5.3.130.0100.06014.68
5.3.120.0100.03314.53
5.3.110.0030.04314.64
5.3.100.0030.08014.11
5.3.90.0070.07013.98
5.3.80.0130.06714.18
5.3.70.0100.03714.11
5.3.60.0130.07013.96
5.3.50.0030.08014.00
5.3.40.0030.03714.04
5.3.30.0230.03714.05
5.3.20.0100.07013.69
5.3.10.0070.06713.80
5.3.00.0070.07313.64
5.2.170.0130.05311.28
5.2.160.0130.04011.24
5.2.150.0000.03311.16
5.2.140.0070.05711.23
5.2.130.0070.04711.04
5.2.120.0030.03311.12
5.2.110.0030.06011.04
5.2.100.0070.03011.06
5.2.90.0100.02711.27
5.2.80.0030.04711.18
5.2.70.0070.06011.13
5.2.60.0000.03711.11
5.2.50.0000.05710.94
5.2.40.0030.06010.96
5.2.30.0000.06310.86
5.2.20.0030.05311.02
5.2.10.0070.06011.00
5.2.00.0100.05310.76
5.1.60.0030.03310.09
5.1.50.0070.03710.02
5.1.40.0070.0439.99
5.1.30.0030.03010.43
5.1.20.0000.05010.45
5.1.10.0130.04310.14
5.1.00.0030.04310.16
5.0.50.0000.0338.65
5.0.40.0030.0278.31
5.0.30.0030.0308.35
5.0.20.0000.0278.35
5.0.10.0000.0238.24
5.0.00.0000.0408.28
4.4.90.0000.0308.07
4.4.80.0100.0108.07
4.4.70.0000.0208.07
4.4.60.0030.0308.07
4.4.50.0000.0178.07
4.4.40.0000.0538.07
4.4.30.0000.0208.07
4.4.20.0030.0338.07
4.4.10.0000.0308.07
4.4.00.0000.0278.07
4.3.110.0000.0178.07
4.3.100.0000.0308.07
4.3.90.0000.0208.07
4.3.80.0030.0438.07
4.3.70.0000.0178.07
4.3.60.0030.0338.07
4.3.50.0000.0178.07
4.3.40.0030.0238.07
4.3.30.0000.0208.07
4.3.20.0000.0338.07
4.3.10.0000.0208.07
4.3.00.0000.0338.07

preferences:
45.32 ms | 401 KiB | 5 Q