Skip to content

Instantly share code, notes, and snippets.

@dprevite
Created May 8, 2014 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dprevite/f57926570553107f4ead to your computer and use it in GitHub Desktop.
Save dprevite/f57926570553107f4ead to your computer and use it in GitHub Desktop.
parse_brackets.php
<?php
function parse() {
$special = [
'[' => ']',
'{' => '}',
'(' => ')'
];
$string = str_split('(())');
$opening = 0;
foreach ($string as $character) {
if (in_array($character, array_keys($special))) {
$opening++;
}
if (in_array($character, $special)) {
$opening--;
}
}
return ($opening == 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment