3v4l.org

run code in 300+ PHP versions simultaneously
<?php function braceCheck(array $values) : array { for ($i = 0; $i <= count($values) - 1; $i++) { $braces = str_split($values[$i]); $values[$i] = isValid($braces); } return $values; } function isValid(array $braces) : string { $available = ['{' => '}', '(' => ')', '[' => ']']; $opened = []; $closed = []; for ($i = 0; $i <= count($braces) - 1; $i++) { if (in_array($braces[$i], array_keys($available))) { $opened[] = $braces[$i]; continue; } $closed[] = $braces[$i]; } return match($braces, $available, $opened, $closed); } function match($braces, array $available, array $opened, array $closed) : string { $last_open = $opened[count($opened) - 1]; $opened = array_values($opened); $closed = array_values($closed); if(!testValidity($braces, $available, $last_open, $opened, $closed)) { return 'NO'; } if (count($opened) > 1) { $result = match( $braces, $available, array_slice($opened, 0, -1), array_slice($closed, 1) ); } return 'YES'; } function testValidity($braces, array $available, string $last_open, array $opened, array $closed) : bool { echo $closed[0]; $arr = array_slice($braces, 0, strpos($closed[0], $braces)); $flipped = array_flip($available); vardump($arr, $flipped); in_array($arr, $flipped[$closed[0]]); // check if not nested properly if ($available[$last_open] !== $closed[0]) { // check if the brackets are consecutive if ($available[$opened[0]] === $closed[0]) { return true; } return false; } // check if the brackets are not consecutive if ($available[$opened[0]] !== $closed[0]) { // check if nested properly if ($available[$last_open] === $closed[0]) { return true; } return false; } return true; } $values = ['{[()]}', '{[(]}', '{}()[]', '{]}[']; // YES, NO, YES, NO var_dump(braceCheck($values)); ?>

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.01218.18
8.3.50.0100.00616.09
8.3.40.0040.01118.79
8.3.30.0090.00918.84
8.3.20.0040.00419.10
8.3.10.0080.00021.04
8.3.00.0090.00019.68
8.2.180.0120.00418.41
8.2.170.0140.00722.96
8.2.160.0090.00620.82
8.2.150.0090.00025.66
8.2.140.0000.00824.66
8.2.130.0040.00419.51
8.2.120.0080.00026.35
8.2.110.0030.00620.52
8.2.100.0150.00017.59
8.2.90.0040.00417.48
8.2.80.0060.00318.66
8.2.70.0030.00517.77
8.2.60.0060.00317.80
8.2.50.0000.00718.10
8.2.40.0030.00621.13
8.2.30.0000.00719.28
8.2.20.0040.00417.88
8.2.10.0040.00417.94
8.2.00.0000.00719.27
8.1.280.0140.00725.92
8.1.270.0000.00823.96
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0030.00719.36
8.1.230.0090.00320.93
8.1.220.0050.00318.23
8.1.210.0080.00018.77
8.1.200.0050.00317.23
8.1.190.0060.00317.11
8.1.180.0050.00318.10
8.1.170.0090.00018.50
8.1.160.0030.00518.74
8.1.150.0000.00718.73
8.1.140.0000.00717.54
8.1.130.0030.00318.93
8.1.120.0020.00517.24
8.1.110.0050.00317.24
8.1.100.0000.00717.25
8.1.90.0070.00017.20
8.1.80.0040.00417.20
8.1.70.0030.00317.26
8.1.60.0060.00317.45
8.1.50.0040.00417.37
8.1.40.0070.00417.38
8.1.30.0030.00517.54
8.1.20.0040.00417.48
8.1.10.0030.00617.32
8.1.00.0030.00517.44
8.0.300.0060.00318.77
8.0.290.0070.00017.05
8.0.280.0070.00018.26
8.0.270.0000.00817.04
8.0.260.0000.00617.27
8.0.250.0000.00716.84
8.0.240.0040.00416.82
8.0.230.0030.00316.92
8.0.220.0020.00716.89
8.0.210.0040.00416.85
8.0.200.0060.00016.98
8.0.190.0070.00016.82
8.0.180.0070.00016.81
8.0.170.0050.00316.89
8.0.160.0070.00016.87
8.0.150.0000.01116.73
8.0.140.0000.00716.80
8.0.130.0030.00313.31
8.0.120.0030.00316.78
8.0.110.0000.00716.85
8.0.100.0040.00416.86
8.0.90.0040.00416.93
8.0.80.0080.01016.87
8.0.70.0070.00016.77
8.0.60.0000.00716.71
8.0.50.0000.00716.83
8.0.30.0110.00816.86
8.0.20.0090.01017.40
8.0.10.0040.00416.88
8.0.00.0070.01116.69
7.4.330.0050.00015.55
7.4.320.0070.00016.55
7.4.300.0000.00616.52
7.4.290.0000.00716.64
7.4.280.0040.00316.58
7.4.270.0070.00016.53
7.4.260.0070.00316.43
7.4.250.0070.00016.59
7.4.240.0050.00216.54
7.4.230.0000.00816.72
7.4.220.0070.00016.64
7.4.210.0080.00816.59
7.4.200.0000.00716.43
7.4.160.0050.01216.64
7.4.140.0090.01017.86
7.4.130.0090.01216.55
7.4.120.0110.00816.57
7.4.110.0140.00616.39
7.4.100.0070.01016.78
7.4.90.0140.00616.59
7.4.80.0030.01319.39
7.4.70.0080.00816.39
7.4.60.0120.00916.32
7.4.50.0100.00416.29
7.4.40.0130.00416.41
7.4.10.0050.01314.69
7.4.00.0080.00814.92
7.3.330.0030.00313.48
7.3.320.0070.00013.31
7.3.310.0030.00316.34
7.3.300.0040.00416.32
7.3.290.0040.00416.46
7.3.280.0100.00816.40
7.3.260.0150.00616.55
7.3.240.0060.01116.50
7.3.230.0090.00916.41
7.3.210.0060.01016.45
7.3.200.0140.01016.48
7.3.190.0030.01816.53
7.3.180.0070.01016.38
7.3.170.0100.00716.49
7.3.160.0070.01316.62
7.3.130.0080.00914.87
7.3.120.0050.01314.97
7.3.110.0070.01214.92
7.3.100.0050.01014.70
7.3.90.0110.00214.72
7.3.80.0100.00314.86
7.3.70.0070.00714.85
7.3.60.0090.00414.87
7.3.50.0070.00714.79
7.3.40.0020.00914.82
7.3.30.0030.01014.73
7.3.20.0030.00916.67
7.3.10.0090.00516.56
7.3.00.0030.01016.63
7.2.330.0230.00916.54
7.2.320.0070.01016.87
7.2.310.0060.01916.89
7.2.300.0030.01316.67
7.2.290.0080.01216.87
7.2.260.0040.01414.86
7.2.250.0100.00915.09
7.2.240.0050.01015.27
7.2.230.0090.00815.07
7.2.220.0030.01015.04
7.2.210.0110.00315.21
7.2.200.0060.00515.03
7.2.190.0090.00615.00
7.2.180.0070.01215.26
7.2.170.0060.00615.24
7.2.160.0050.01015.20
7.2.150.0080.00516.98
7.2.140.0050.00716.74
7.2.130.0060.00916.93
7.2.120.0000.01716.73
7.2.110.0060.00816.78
7.2.100.0030.01316.87
7.2.90.0020.01317.12
7.2.80.0090.00816.93
7.2.70.0030.01016.88
7.2.60.1780.00816.38
7.2.50.1710.01016.28
7.2.40.2150.00816.32
7.2.30.1760.00516.45
7.2.20.2130.00816.43
7.2.10.2290.00716.54
7.2.00.2050.00816.44
7.1.330.0020.01115.67
7.1.320.0040.00515.76
7.1.310.0060.00715.93
7.1.300.0020.01115.74
7.1.290.0080.00515.66
7.1.280.0050.00715.71
7.1.270.0010.01415.87
7.1.260.0100.00315.75
7.1.250.0030.01215.82
7.1.240.0040.00815.95
7.1.230.0000.01315.92
7.1.220.0050.01015.79
7.1.210.0060.00615.69
7.1.200.0070.00715.73
7.1.190.0070.00715.73
7.1.180.0080.00315.82
7.1.170.2570.00614.95
7.1.160.2170.01116.04
7.1.150.2210.00915.99
7.1.140.2250.01116.28
7.1.130.2420.00716.17
7.1.120.1860.01316.10
7.1.110.2060.00915.84
7.1.100.1950.00716.00
7.1.90.3510.00816.13
7.1.80.2960.01115.76
7.1.70.3020.00815.64
7.1.60.2890.01021.67
7.1.50.4180.01221.49
7.1.40.4480.01021.42
7.1.30.4690.00821.54
7.1.20.4690.00921.31
7.1.10.4110.00615.40
7.1.00.2180.00615.37
7.0.330.0050.00715.53
7.0.320.0040.00915.42
7.0.310.0010.01015.33
7.0.300.0060.00815.24
7.0.290.0040.00915.32
7.0.280.0090.00315.33
7.0.270.0060.00515.44
7.0.260.0070.00715.46
7.0.250.0060.00615.43
7.0.240.0040.00915.31
7.0.230.0040.00815.42
7.0.220.0030.00715.33
7.0.210.0080.00515.39
7.0.200.0050.00615.55
7.0.190.0080.00715.39
7.0.180.0000.01215.47
7.0.170.0070.00415.49
7.0.160.0010.00915.41
7.0.150.0110.00215.21
7.0.140.0050.00715.42
7.0.130.0050.00815.52
7.0.120.0050.00715.53
7.0.110.0080.00515.49
7.0.100.0020.01215.50
7.0.90.0040.00815.28
7.0.80.0050.00715.45
7.0.70.0040.00815.53
7.0.60.0050.01015.36
7.0.50.0030.00615.54
7.0.40.0030.00913.53
7.0.30.0060.00513.30
7.0.20.0080.00513.50
7.0.10.0070.00713.60
7.0.00.0030.00813.38
5.6.400.0050.00814.18
5.6.390.0070.00713.99
5.6.380.0080.00614.06
5.6.370.0050.00914.05
5.6.360.0050.00514.24
5.6.350.0040.01014.18
5.6.340.0060.00613.81
5.6.330.0080.00414.27
5.6.320.0070.00514.04
5.6.310.0040.01113.85
5.6.300.0060.00814.18
5.6.290.0090.00513.95
5.6.280.0050.00814.18
5.6.270.0080.00414.07
5.6.260.0050.01114.29
5.6.250.0070.00314.24
5.6.240.0040.00814.14
5.6.230.0000.01514.16
5.6.220.0050.00914.22
5.6.210.0050.01114.00
5.6.200.0040.00814.21
5.6.190.0090.00514.01
5.6.180.0050.00813.86
5.6.170.0040.00614.00
5.6.160.0040.00714.01
5.6.150.0050.00614.01
5.6.140.0020.00614.13
5.6.130.0060.00614.11
5.6.120.0070.00713.93
5.6.110.0050.01113.98
5.6.100.0030.00614.07
5.6.90.0080.00614.19
5.6.80.0070.00914.08
5.6.70.0030.00913.93
5.6.60.0090.00714.11
5.6.50.0080.00614.01
5.6.40.0060.00913.76
5.6.30.0050.00613.93
5.6.20.0050.00914.15
5.6.10.0050.00713.96
5.6.00.0050.00913.89

preferences:
47.62 ms | 401 KiB | 5 Q