Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check bracket correct open and close

function check_brackets_balance($string, $bracket_map = false) {
    $bracket_map = $bracket_map ?: [ '[' => ']', '{' => '}', '(' => ')' ];
    $bracket_map_flipped = array_flip($bracket_map);
    $length = mb_strlen($string);
    $brackets_stack = [];
    for ($i = 0; $i < $length; $i++) {
        $current_char = $string[$i];
        if (isset($bracket_map[$current_char])) {
            $brackets_stack[] = $bracket_map[$current_char];
        } else if (isset($bracket_map_flipped[$current_char])) {
            $expected = array_pop($brackets_stack);
            if (($expected === NULL) || ($current_char != $expected)) {
                return false;
            }
        }
    }
    return empty($brackets_stack);
}
Comment

PREVIOUS NEXT
Code Example
Php :: PHP force refresh image 
Php :: subdomain ajax request fail in php 
Php :: laravel save or post 
Php :: larqavel migration 
Php :: undefine variable $variable in php 
Php :: laravel list get x amount in a collection 
Php :: TypeError: Argument 1 passed to DrupalCoreEntityEntityViewBuilder::view() must implement interface 
Php :: phpmaker check master details page 
Php :: composer exceeded the timeout of 300 seconds. 
Php :: Inject interface and not concrete class 
Php :: laravel belongsto nested 
Php :: Laravel delete old file 
Php :: laravel eloquent pass to next element 
Php :: How To Substract And Add Hours In Laravel Using Carabon? 
Php :: Yii2 Dynamic Relational Query 
Php :: php getUserStateFromRequest 
Php :: Primary Termlaravel recursive relationships 
Php :: $this meaning in codeigniter 
Php :: get data in two columns in div in loop php 
Php :: generate hash password in laravel online 
Php :: ajax call php bootstrap validation 
Php :: wc php free shipping function 
Php :: cara cek versi php di laptop 
Php :: symfony refresh endpoints 
Php :: laravel find user by id 
Php :: mobibeDetect 
Php :: was loaded over https, but requested an insecure xmlhttprequest endpoint laravel 
Php :: how to convert number into million and billion suffix in PHP using brick/Money package 
Php :: X-Frame-Options may only be set via an HTTP header sent along with a document. It may not be set inside <meta. 
Php :: why php $_session in not working in react js 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =