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); if($depth == 1) { $stackedArray[$key] = $array[0]; // that's a single value } else { $subArray = $this->_stack($array); if($subArray != null) { $stackedArray[$key] = $subArray; } } // save key to find duplicated if(!$this->_saveDepthKey($key, $depth)) return null; 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.0060.00918.55
8.3.50.0260.00516.70
8.3.40.0110.01118.76
8.3.30.0180.00418.84
8.3.20.0040.00418.77
8.3.10.0110.00020.65
8.3.00.0030.00719.13
8.2.180.0120.00317.00
8.2.170.0070.00722.96
8.2.160.0120.00318.95
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0060.00326.16
8.2.120.0080.00318.96
8.2.110.0040.00420.90
8.2.100.0040.00818.03
8.2.90.0080.00019.29
8.2.80.0080.00019.28
8.2.70.0110.00017.50
8.2.60.0000.00817.93
8.2.50.0040.00418.07
8.2.40.0040.00418.22
8.2.30.0060.00318.12
8.2.20.0040.00717.70
8.2.10.0080.00017.82
8.2.00.0000.00917.70
8.1.280.0090.00625.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.01122.12
8.1.230.0070.00420.91
8.1.220.0000.00918.77
8.1.210.0030.00519.09
8.1.200.0060.00317.35
8.1.190.0000.00817.63
8.1.180.0050.00318.10
8.1.170.0000.00818.88
8.1.160.0040.00419.01
8.1.150.0050.00318.57
8.1.140.0080.00017.51
8.1.130.0030.00317.84
8.1.120.0000.00817.53
8.1.110.0040.00417.36
8.1.100.0030.00317.41
8.1.90.0000.00717.48
8.1.80.0040.00417.45
8.1.70.0030.00617.46
8.1.60.0040.00417.57
8.1.50.0040.00417.52
8.1.40.0040.00417.54
8.1.30.0080.00017.50
8.1.20.0030.00517.66
8.1.10.0040.00417.59
8.1.00.0050.00317.50
8.0.300.0000.00719.79
8.0.290.0000.00816.75
8.0.280.0030.00318.47
8.0.270.0040.00417.34
8.0.260.0030.00316.82
8.0.250.0040.00417.04
8.0.240.0070.00016.97
8.0.230.0030.00317.04
8.0.220.0000.00717.00
8.0.210.0070.00016.87
8.0.200.0000.00717.05
8.0.190.0070.00017.10
8.0.180.0000.00716.89
8.0.170.0050.00316.80
8.0.160.0080.00017.01
8.0.150.0050.00516.77
8.0.140.0050.00216.93
8.0.130.0000.00613.37
8.0.120.0000.00916.84
8.0.110.0070.00017.02
8.0.100.0000.00716.96
8.0.90.0000.00716.78
8.0.80.0100.01016.96
8.0.70.0050.00217.00
8.0.60.0000.00716.95
8.0.50.0040.00416.96
8.0.30.0030.01416.93
8.0.20.0020.01617.36
8.0.10.0040.00416.98
8.0.00.0070.01116.79
7.4.330.0000.00512.99
7.4.320.0000.00616.55
7.4.300.0040.00416.59
7.4.290.0050.00316.63
7.4.280.0040.00816.59
7.4.270.0000.00716.57
7.4.260.0000.00613.27
7.4.250.0060.00316.50
7.4.240.0040.00416.70
7.4.230.0000.00716.60
7.4.220.0050.01016.43
7.4.210.0090.00616.57
7.4.200.0070.00016.64
7.4.190.0020.00516.63
7.4.160.0000.01616.63
7.4.150.0140.00316.53
7.4.140.0110.00616.52
7.4.130.0060.01016.52
7.4.120.0100.00716.51
7.4.110.0060.01216.69
7.4.100.0090.01416.63
7.4.90.0090.00916.59
7.4.80.0110.00819.39
7.4.70.0070.01016.56
7.4.60.0030.01316.43
7.4.50.0060.00316.46
7.4.40.0050.00916.52
7.4.30.0090.00816.65
7.4.00.0080.00814.66
7.3.330.0060.00013.30
7.3.320.0060.00013.34
7.3.310.0040.00416.29
7.3.300.0040.00416.49
7.3.290.0050.01216.42
7.3.280.0110.00816.41
7.3.270.0090.00916.43
7.3.260.0100.01316.42
7.3.250.0120.00916.67
7.3.240.0040.01716.49
7.3.230.0100.01116.47
7.3.210.0120.00416.52
7.3.200.0150.00016.49
7.3.190.0030.01516.43
7.3.180.0040.01216.54
7.3.170.0090.01216.50
7.3.160.0100.00716.40
7.3.120.0100.00615.00
7.2.330.0090.00916.48
7.2.320.0090.00916.80
7.2.310.0110.01216.60
7.2.300.0140.00416.87
7.2.290.0080.00816.55
7.1.70.0080.00417.11
7.1.60.0130.01319.30
7.1.50.0060.01616.76
7.1.00.0030.07022.54
7.0.200.0190.00414.97
7.0.140.0070.07022.02
7.0.120.0030.06722.09
7.0.60.0170.07319.95
7.0.50.0000.09317.86
7.0.40.0070.08720.12
7.0.30.0230.05320.08
7.0.20.0230.04020.22
7.0.10.0100.08720.24
7.0.00.0070.05020.09
5.6.280.0030.07321.00
5.6.210.0070.08020.74
5.6.200.0030.04718.18
5.6.190.0170.04020.49
5.6.180.0170.08020.39
5.6.170.0370.07320.52
5.6.160.0130.05720.44
5.6.150.0170.07018.19
5.6.140.0070.04318.14
5.6.130.0070.07018.17
5.6.120.0100.08321.00
5.6.110.0070.08721.08
5.6.100.0070.08720.98
5.6.90.0000.04321.04
5.6.80.0130.05720.29
5.5.350.0100.07320.54
5.5.340.0100.07717.96
5.5.330.0070.04320.28
5.5.320.0400.05320.42
5.5.310.0270.07020.19
5.5.300.0030.08318.02
5.5.290.0070.08317.98
5.5.280.0170.07720.88
5.5.270.0100.05020.90
5.5.260.0070.05320.86
5.5.250.0030.08020.68
5.5.240.0270.07320.17
5.4.450.0000.06719.41
5.4.440.0030.06319.21
5.4.430.0070.05019.57
5.4.420.0070.08319.30
5.4.410.0030.06719.17
5.4.400.0070.06318.99
5.4.390.0030.04019.16
5.4.380.0030.04019.20
5.4.370.0130.07318.86
5.4.360.0130.06318.98
5.4.350.0030.03719.22
5.4.340.0100.03719.15
5.4.320.0070.05019.15
5.4.310.0130.05018.84
5.4.300.0100.07719.23
5.4.290.0170.06718.85
5.4.280.0100.06019.20
5.4.270.0070.07318.86
5.4.260.0070.07718.97
5.4.250.0070.06019.00
5.4.240.0030.08319.07
5.4.230.0130.07319.23
5.4.220.0100.05319.00
5.4.210.0030.07719.23
5.4.200.0070.04318.91
5.4.190.0030.05018.91
5.4.180.0030.08019.00
5.4.170.0070.07018.99
5.4.160.0070.08019.12
5.4.150.0100.04319.13
5.4.140.0030.04016.34
5.4.130.0000.03716.31
5.4.120.0130.04716.43
5.4.110.0070.07016.34
5.4.100.0030.06316.30
5.4.90.0070.07016.39
5.4.80.0070.07716.29
5.4.70.0030.03716.44
5.4.60.0130.03316.38
5.4.50.0100.05716.39
5.4.40.0130.05016.28
5.4.30.0030.04716.51
5.4.20.0000.07716.31
5.4.10.0030.07716.27
5.4.00.0000.07315.80
5.3.290.0000.07714.72
5.3.280.0130.07014.66
5.3.270.0030.08314.67
5.3.260.0000.06714.70
5.3.250.0030.03714.64
5.3.240.0030.03714.64
5.3.230.0000.04714.62
5.3.220.0070.08314.59
5.3.210.0030.08314.64
5.3.200.0100.06714.63
5.3.190.0030.04714.59
5.3.180.0100.04714.65
5.3.170.0000.04714.59
5.3.160.0030.08014.60
5.3.150.0030.05014.59
5.3.140.0100.06014.57
5.3.130.0000.07314.51
5.3.120.0100.07314.58
5.3.110.0030.07314.57
5.3.100.0030.07714.06
5.3.90.0070.05014.09
5.3.80.0070.07314.04
5.3.70.0130.06013.93
5.3.60.0130.05014.08
5.3.50.0100.07013.97
5.3.40.0030.04714.12
5.3.30.0100.07013.93
5.3.20.0070.07013.66
5.3.10.0070.03713.69
5.3.00.0030.05313.72
5.2.170.0030.06711.19
5.2.160.0000.03311.33
5.2.150.0030.03711.11
5.2.140.0030.04011.23
5.2.130.0030.06311.18
5.2.120.0070.05311.30
5.2.110.0100.06011.05
5.2.100.0070.02711.29
5.2.90.0030.03311.13
5.2.80.0030.04711.18
5.2.70.0070.02711.12
5.2.60.0070.05010.96
5.2.50.0070.03010.93
5.2.40.0100.05711.04
5.2.30.0000.04311.06
5.2.20.0070.05711.04
5.2.10.0070.02310.90
5.2.00.0100.03710.71
5.1.60.0070.04710.09
5.1.50.0000.0639.98
5.1.40.0130.04010.07
5.1.30.0100.03310.37
5.1.20.0030.03010.44
5.1.10.0000.03010.24
5.1.00.0030.03010.08
5.0.50.0030.0208.61
5.0.40.0030.0178.44
5.0.30.0070.0278.35
5.0.20.0030.0238.33
5.0.10.0030.0238.33
5.0.00.0000.0338.33
4.4.90.0000.0178.03
4.4.80.0030.0178.04
4.4.70.0000.0178.11
4.4.60.0030.0238.12
4.4.50.0000.0378.12
4.4.40.0030.0508.20
4.4.30.0030.0308.22
4.4.20.0000.0308.27
4.4.10.0030.0138.31
4.4.00.0000.0278.33
4.3.110.0030.0208.33
4.3.100.0000.0378.33
4.3.90.0000.0138.33
4.3.80.0000.0278.33
4.3.70.0000.0138.33
4.3.60.0000.0178.33
4.3.50.0070.0108.33
4.3.40.0000.0308.33
4.3.30.0000.0308.33
4.3.20.0000.0378.33
4.3.10.0000.0178.33
4.3.00.0000.0238.33

preferences:
64.99 ms | 400 KiB | 5 Q