3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function isCorrect($string) { $wait = array(); for ($i = 0; $i < strlen($string); $i++) { if ($string[$i] == '{') { array_push($wait, '}'); } elseif ($string[$i] == '(') { array_push($wait, ')'); } elseif ($string[$i] == '}' && end($wait) == '}') { array_pop($wait); } elseif ($string[$i] == ')' && end($wait) == ')') { array_pop($wait); } elseif ($string[$i] == ')' || $string[$i] == '}') { return false; } } return empty($wait); } assert(isCorrect('') === true); assert(isCorrect('()') === true); assert(isCorrect('{()}') === true); assert(isCorrect('{()}{}') === true); assert(isCorrect('(())') === true); assert(isCorrect('{({({({()})})})}') === true); assert(isCorrect('{(})') === false);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0