1

I'm attempting to implement in php the C parentheses balancer described at https://stackoverflow.com/a/2718114/1507339

as seen below


function match ($string, $index)
{
    if (isset($string[$index]) == false){ return ""; }
    if ($string[$index] == "}") { return "}"; }
    if ($string[$index] == "{")
    {
        $closer = match($string, ++$index);
        if ($closer == "}"){
            return match($closer, ++$index);
    }
    return $index - 1;
    }
    return match($string, ++$index);
}

and it's run as

$string = "{hey}}";
echo match($string, 0);

where the location of the first opening brace without a close is printed to the screen. This doesn't happen and I'm not sure why, any help?

Community
  • 1
  • 1

0 Answers0