3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function match($available, $opened, $closed) { $last_open = $opened[count($opened) - 1]; if ($available[$last_open] !== $closed[0]) { return 'NO'; } match($available, array_slice($opened, 0, -1), array_slice($closed, 1)); return 'YES'; } function isValid($braces) { $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($available, $opened, $closed); } function braceCheck($values) { for ($i = 0; $i < count($values) - 1; $i++) { $braces = str_split($value); $values[$i] = isValid($braces); } return $values; } echo 'dessert\n'; $values = ['{}()[]', '{]}[']; var_dump($values); ?>
based on 2CB7K
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0alpha1
dessert\narray(2) { [0]=> string(6) "{}()[]" [1]=> string(4) "{]}[" }