=0; $index-- ) { if ( $str[$index] == '(' ) { ++$tree; } else { $tree--; } if ( $tree == 0 ) { echo $index +1 . PHP_EOL; break; } } }