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 { $position = strpos($braces, $closed[0]); echo $position; $arr = array_slice($braces, 0, $position); $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.0070.01518.68
8.3.50.0110.00316.15
8.3.40.0120.00318.84
8.3.30.0100.00618.65
8.3.20.0000.00719.07
8.3.10.0070.00020.91
8.3.00.0090.00017.80
8.2.180.0090.00618.06
8.2.170.0170.00322.96
8.2.160.0110.00320.82
8.2.150.0060.00325.66
8.2.140.0000.00824.66
8.2.130.0040.00419.82
8.2.120.0040.00426.35
8.2.110.0060.00321.02
8.2.100.0110.00017.78
8.2.90.0060.00317.47
8.2.80.0000.01118.59
8.2.70.0000.00817.66
8.2.60.0050.00318.09
8.2.50.0000.00918.10
8.2.40.0030.00619.15
8.2.30.0000.00819.27
8.2.20.0000.00717.86
8.2.10.0040.00417.96
8.2.00.0020.00519.31
8.1.280.0090.00925.92
8.1.270.0000.00923.70
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0040.00817.32
8.1.230.0030.00917.83
8.1.220.0060.00317.74
8.1.210.0060.00318.77
8.1.200.0030.00617.23
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0050.00518.46
8.1.160.0040.00420.56
8.1.150.0000.00718.79
8.1.140.0040.00417.65
8.1.130.0000.00718.90
8.1.120.0000.00817.32
8.1.110.0070.00017.28
8.1.100.0000.00717.29
8.1.90.0040.00417.34
8.1.80.0070.00017.25
8.1.70.0070.00017.34
8.1.60.0040.00417.44
8.1.50.0080.00017.39
8.1.40.0070.00317.34
8.1.30.0030.00617.39
8.1.20.0050.00217.32
8.1.10.0040.00417.41
8.1.00.0050.00217.37
8.0.300.0000.00720.16
8.0.290.0040.00416.75
8.0.280.0000.00718.35
8.0.270.0070.00017.15
8.0.260.0040.00417.12
8.0.250.0030.00316.92
8.0.240.0000.00716.97
8.0.230.0030.00316.96
8.0.220.0080.00316.65
8.0.210.0070.00016.75
8.0.200.0030.00316.89
8.0.190.0040.00416.83
8.0.180.0030.00516.88
8.0.170.0060.00316.77
8.0.160.0040.00416.78
8.0.150.0030.00616.87
8.0.140.0070.00016.87
8.0.130.0000.00513.34
8.0.120.0040.00416.79
8.0.110.0050.00316.72
8.0.100.0070.00016.73
8.0.90.0040.00416.86
8.0.80.0130.00616.77
8.0.70.0020.00516.91
8.0.60.0000.00716.89
8.0.50.0000.00816.72
8.0.30.0130.00716.95
8.0.20.0130.00517.40
8.0.10.0040.00416.89
8.0.00.0110.00716.64
7.4.330.0020.00215.55
7.4.320.0030.00316.44
7.4.300.0060.00016.67
7.4.290.0030.00316.63
7.4.280.0050.00316.52
7.4.270.0040.00416.63
7.4.260.0040.00416.65
7.4.250.0000.00716.34
7.4.240.0070.00016.63
7.4.230.0030.00316.45
7.4.220.0000.00716.41
7.4.210.0140.00716.60
7.4.200.0080.00016.44
7.4.160.0070.01116.64
7.4.140.0110.00917.86
7.4.130.0100.01316.60
7.4.120.0100.00716.59
7.4.110.0150.00916.38
7.4.100.0110.00516.57
7.4.90.0060.01216.61
7.4.80.0090.00919.39
7.4.70.0130.00416.68
7.4.60.0070.01416.54
7.4.50.0060.01216.57
7.4.40.0090.00816.53
7.4.00.0090.00614.83
7.3.330.0030.00313.52
7.3.320.0060.00313.23
7.3.310.0030.00316.51
7.3.300.0070.00016.49
7.3.290.0070.00016.34
7.3.280.0120.00816.36
7.3.260.0120.00716.53
7.3.240.0050.01416.49
7.3.230.0110.00616.64
7.3.210.0090.00916.40
7.3.200.0140.00316.70
7.3.190.0040.01216.55
7.3.180.0090.00916.64
7.3.170.0060.01016.59
7.3.160.0170.00316.49
7.3.10.0070.00716.25
7.3.00.0060.00716.33
7.2.330.0130.01016.52
7.2.320.0110.00716.82
7.2.310.0090.01016.79
7.2.300.0170.00516.62
7.2.290.0030.01516.83
7.2.130.0000.01116.67
7.2.120.0120.00316.19
7.2.110.0090.00616.58
7.2.100.0080.01116.37
7.2.90.0080.00816.37
7.2.80.0060.01216.80
7.2.70.0110.00316.75
7.2.60.1110.00415.72
7.2.50.0490.00815.82
7.2.40.0580.01215.97
7.2.30.0490.00916.15
7.2.20.0530.00916.11
7.2.10.0470.01015.98
7.2.00.0490.00816.09
7.1.250.0090.00615.67
7.1.200.0090.00315.83
7.1.170.1250.00913.60
7.1.160.0920.00816.51
7.1.150.0990.00717.00
7.1.140.1000.01417.17
7.1.130.1000.01117.08
7.1.120.0760.00716.81
7.1.110.0840.01615.81
7.1.100.1240.01316.34
7.1.90.0850.01215.93
7.1.80.1400.01116.22
7.1.70.1170.01115.30
7.1.60.1750.01833.20
7.1.50.1450.01533.11
7.1.40.1140.01332.38
7.1.30.1110.01832.70
7.1.20.1530.00832.79
7.1.10.1030.00714.79
7.1.00.1330.01314.85

preferences:
57.79 ms | 401 KiB | 5 Q