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 { $subArray = $this->_stack($array); if($subArray != null) { $stackedArray[$key] = $subArray; } } 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.0110.00716.88
8.3.50.0110.00917.47
8.3.40.0090.00918.96
8.3.30.0070.00718.64
8.3.20.0040.00418.70
8.3.10.0050.00320.49
8.3.00.0030.00719.38
8.2.180.0160.00317.00
8.2.170.0070.00722.96
8.2.160.0160.00322.08
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0130.00319.89
8.2.110.0100.00020.99
8.2.100.0070.00417.84
8.2.90.0030.00621.07
8.2.80.0040.00417.89
8.2.70.0060.00317.63
8.2.60.0060.00317.93
8.2.50.0030.00718.07
8.2.40.0030.00518.06
8.2.30.0000.00718.03
8.2.20.0000.00717.76
8.2.10.0070.00017.88
8.2.00.0070.00417.81
8.1.280.0030.01225.92
8.1.270.0080.00024.66
8.1.260.0060.00326.35
8.1.250.0050.00228.09
8.1.240.0060.00322.59
8.1.230.0080.00420.88
8.1.220.0050.00317.79
8.1.210.0050.00318.93
8.1.200.0110.00017.35
8.1.190.0000.00817.41
8.1.180.0080.00018.10
8.1.170.0050.00318.89
8.1.160.0040.00418.82
8.1.150.0060.00318.72
8.1.140.0040.00417.47
8.1.130.0000.00717.83
8.1.120.0080.00017.46
8.1.110.0000.00817.52
8.1.100.0070.00017.38
8.1.90.0040.00417.50
8.1.80.0050.00317.37
8.1.70.0040.00417.46
8.1.60.0100.00017.66
8.1.50.0060.00317.41
8.1.40.0040.00417.52
8.1.30.0040.00417.66
8.1.20.0040.00417.67
8.1.10.0070.00017.59
8.1.00.0040.00417.55
8.0.300.0000.00719.89
8.0.290.0070.00016.75
8.0.280.0000.00718.43
8.0.270.0000.00817.37
8.0.260.0070.00016.91
8.0.250.0040.00417.11
8.0.240.0030.00516.97
8.0.230.0000.00817.06
8.0.220.0030.00316.87
8.0.210.0070.00016.87
8.0.200.0070.00017.05
8.0.190.0000.00717.04
8.0.180.0000.00817.09
8.0.170.0030.00517.06
8.0.160.0000.00716.99
8.0.150.0040.00416.83
8.0.140.0080.00016.92
8.0.130.0050.00013.44
8.0.120.0000.00716.96
8.0.110.0040.00416.84
8.0.100.0080.00017.01
8.0.90.0030.00516.87
8.0.80.0120.00917.06
8.0.70.0000.00717.02
8.0.60.0030.00616.79
8.0.50.0080.00016.77
8.0.30.0110.01117.07
8.0.20.0080.01116.99
8.0.10.0030.00517.11
8.0.00.0110.01016.74
7.4.330.0020.00212.91
7.4.320.0030.00316.52
7.4.300.0000.00616.52
7.4.290.0020.00516.47
7.4.280.0070.00016.47
7.4.270.0000.00916.61
7.4.260.0000.00713.34
7.4.250.0070.00316.62
7.4.240.0040.00416.63
7.4.230.0000.00716.54
7.4.220.0090.01616.68
7.4.210.0060.01016.54
7.4.200.0030.00316.50
7.4.190.0070.00016.66
7.4.160.0140.00316.68
7.4.150.0060.01616.40
7.4.140.0070.01616.40
7.4.130.0080.01116.40
7.4.120.0100.00716.51
7.4.110.0060.01216.66
7.4.100.0070.01416.62
7.4.90.0110.00716.68
7.4.80.0080.00816.55
7.4.70.0090.01216.54
7.4.60.0070.01116.64
7.4.50.0030.00616.55
7.4.40.0030.01016.46
7.4.30.0070.01016.34
7.4.00.0060.00914.87
7.3.330.0000.00613.31
7.3.320.0000.00513.31
7.3.310.0000.00716.34
7.3.300.0000.00716.40
7.3.290.0100.01016.44
7.3.280.0060.01116.38
7.3.270.0060.01216.51
7.3.260.0100.00716.50
7.3.250.0060.01116.46
7.3.240.0170.00316.41
7.3.230.0070.01316.43
7.3.210.0030.01316.42
7.3.200.0100.01319.39
7.3.190.0070.01016.51
7.3.180.0060.01016.36
7.3.170.0040.01816.62
7.3.160.0060.01016.55
7.3.120.0030.01315.00
7.2.330.0090.01316.82
7.2.320.0060.01016.88
7.2.310.0140.01016.89
7.2.300.0030.01516.78
7.2.290.0030.01316.87
7.2.00.0040.00819.30
7.1.100.0030.01317.81
7.1.70.0000.01117.28
7.1.60.0090.01619.40
7.1.50.0130.00017.10
7.1.00.0000.06722.38
7.0.200.1120.00314.73
7.0.140.0000.07722.10
7.0.120.0070.06722.04
7.0.60.0130.06719.85
7.0.50.0030.07017.93
7.0.40.0070.04320.16
7.0.30.0300.07320.16
7.0.20.0230.05320.24
7.0.10.0170.05320.15
7.0.00.0070.07020.09
5.6.280.0070.06720.88
5.6.210.0100.03320.78
5.6.200.0100.06318.14
5.6.190.0000.09020.41
5.6.180.0300.05320.50
5.6.170.0170.04020.58
5.6.160.0030.06320.71
5.6.150.0030.04018.14
5.6.140.0030.08318.16
5.6.130.0130.07718.16
5.6.120.0030.06321.13
5.6.110.0130.08020.99
5.6.100.0100.06720.98
5.6.90.0100.07721.00
5.6.80.0070.03720.29
5.6.70.3830.02720.29
5.5.350.0170.04320.41
5.5.340.0070.08717.93
5.5.330.0030.08720.44
5.5.320.0170.03720.28
5.5.310.0370.06720.35
5.5.300.0070.08017.93
5.5.290.0130.04318.13
5.5.280.0070.07320.78
5.5.270.0030.04320.91
5.5.260.0100.08320.98
5.5.250.0030.04020.51
5.5.240.0130.07320.36
5.4.450.0170.06319.41
5.4.440.0030.05319.56
5.4.430.0070.07719.29
5.4.420.0000.06019.17
5.4.410.0070.05019.44
5.4.400.0130.07019.12
5.4.390.0030.04019.14
5.4.380.0030.08019.10
5.4.370.0100.08019.23
5.4.360.0000.04318.85
5.4.350.0000.04319.01
5.4.340.0000.06718.86
5.4.320.0170.03318.98
5.4.310.0070.06319.22
5.4.300.0070.05318.87
5.4.290.0070.05719.24
5.4.280.0030.07719.14
5.4.270.0070.04318.85
5.4.260.0130.04018.86
5.4.250.0100.07319.00
5.4.240.0070.06018.86
5.4.230.0130.07019.07
5.4.220.0100.07319.11
5.4.210.0070.05319.11
5.4.200.0130.06018.98
5.4.190.0030.07019.11
5.4.180.0070.08019.14
5.4.170.0070.05019.17
5.4.160.0030.04019.06
5.4.150.0030.05319.12
5.4.140.0170.06016.43
5.4.130.0130.06016.41
5.4.120.0100.06016.26
5.4.110.0070.04316.30
5.4.100.0070.06316.43
5.4.90.0130.07016.49
5.4.80.0070.04716.38
5.4.70.0100.06716.47
5.4.60.0030.08016.37
5.4.50.0100.04716.38
5.4.40.0100.06716.38
5.4.30.0130.06016.27
5.4.20.0030.07716.36
5.4.10.0100.04716.36
5.4.00.0070.04015.84
5.3.290.0070.07314.70
5.3.280.0130.06014.67
5.3.270.0000.06314.65
5.3.260.0070.05314.55
5.3.250.0070.04314.66
5.3.240.0000.05714.63
5.3.230.0070.04314.77
5.3.220.0000.05014.75
5.3.210.0170.06314.52
5.3.200.0100.07714.60
5.3.190.0170.06314.64
5.3.180.0070.06714.61
5.3.170.0070.08014.48
5.3.160.0100.07714.61
5.3.150.0070.04714.74
5.3.140.0170.06314.61
5.3.130.0130.06714.63
5.3.120.0070.04314.60
5.3.110.0030.08314.61
5.3.100.0030.08014.05
5.3.90.0100.03314.09
5.3.80.0030.03714.10
5.3.70.0100.04313.99
5.3.60.0170.06314.05
5.3.50.0070.04013.97
5.3.40.0070.07314.02
5.3.30.0070.06313.98
5.3.20.0070.07013.68
5.3.10.0070.06313.70
5.3.00.0070.05313.60
5.2.170.0130.05311.18
5.2.160.0030.05711.23
5.2.150.0030.06011.21
5.2.140.0070.03711.06
5.2.130.0100.05711.20
5.2.120.0030.06311.21
5.2.110.0070.03711.05
5.2.100.0030.06011.18
5.2.90.0070.02711.08
5.2.80.0070.03011.14
5.2.70.0030.03011.29
5.2.60.0100.02311.23
5.2.50.0030.03011.04
5.2.40.0000.04710.98
5.2.30.0030.03010.91
5.2.20.0100.05011.03
5.2.10.0030.03010.96
5.2.00.0030.03010.76
5.1.60.0030.05310.01
5.1.50.0070.0539.98
5.1.40.0000.03010.05
5.1.30.0030.06310.25
5.1.20.0100.05010.53
5.1.10.0030.05310.16
5.1.00.0000.03010.01
5.0.50.0070.0408.73
5.0.40.0030.0438.46
5.0.30.0070.0608.24
5.0.20.0030.0208.23
5.0.10.0070.0378.16
5.0.00.0030.0338.16
4.4.90.0030.0138.16
4.4.80.0000.0378.16
4.4.70.0070.0338.16
4.4.60.0030.0338.16
4.4.50.0030.0308.16
4.4.40.0000.0278.16
4.4.30.0070.0338.16
4.4.20.0030.0278.16
4.4.10.0070.0338.16
4.4.00.0000.0338.16
4.3.110.0030.0378.16
4.3.100.0070.0338.16
4.3.90.0070.0278.16
4.3.80.0030.0278.16
4.3.70.0030.0308.16
4.3.60.0030.0138.16
4.3.50.0030.0238.16
4.3.40.0030.0238.16
4.3.30.0070.0308.16
4.3.20.0000.0178.16
4.3.10.0030.0208.16
4.3.00.0030.0278.16

preferences:
48.86 ms | 401 KiB | 5 Q