Delimiter matching

$string = '({ac[bb]})(){}[]';
var_dump(checkString($string));

function checkString($string)
{
  $open = ['{', '(', '[', '|'];
  $close = ['}', ')', ']', '|'];

  $stack = [];
  for ($i = 0; $i <= strlen($string); $i++) {
    $char = substr($string, $i, 1);

    if (in_array($char, $open)) {
      $stack[] = $char;
    }

    if (in_array($char, $close)) {

      if(empty($stack)) {
        return false;
      }

      $key = array_search($char, $close);

      if($open[$key] = $stack[count($stack)-1]) {
        array_pop($stack);
        continue;
      }
      return false;
    }
  }

  if (empty($stack)) {
    return true;
  }
  return false;
}
    
index