src/Nuffle.php
private function _is_balanced($input) {
    $balance = 0;

    foreach ( str_split($input) as $char ) {
      if ( $char == '(' ) {
        $balance++;
      } else if ( $char == ')' ) {
        $balance--;
      }

      // found a close paren without a matching open paren,
      // no need to continue further
      if ( $balance < 0 ) {
        break;
      }
    }

    return $balance === 0;
  }
private function _is_balanced($input) {
    $balance = 0;

    foreach ( str_split($input) as $char ) {
      if ( $char == '(' ) {
        $balance++;
      } else if ( $char == ')' ) {
        $balance--;
      }

      // found a close paren without a matching open paren,
      // no need to continue further
      if ( $balance < 0 ) {
        break;
      }
    }

    return $balance === 0;
  }
private function _is_balanced ( $ input ) { $ balance = 0 ; foreach ( str_split ( $ input ) as $ char ) { if ( $ char == '(' ) { $ balance ++ ; } else if ( $ char == ')' ) { $ balance -- ; } // found a close paren without a matching open paren, // no need to continue further if ( $ balance < 0 ) { break ; } } return $ balance === 0 ; }
Check if equation has balanced parens

@param  string  $input User input
@return boolean        Whether or not the parens are balanced
Check if equation has balanced parens