Created
October 16, 2018 06:56
-
-
Save sorbing/919d8c54461019398beeecf67c08c70b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// @note Test #1 | |
// Example usage: php brackets-checker.php '({()}[])' | |
$expressions = [ | |
'()]', | |
'()[]', | |
'(}', | |
'({[]})', | |
'[1+2(4*3{2/4[88+0]})]', | |
]; | |
if ($argc == 2) { | |
$expressions = [$argv[1]]; | |
} | |
foreach ($expressions as $expression) { | |
$brackets = preg_replace('/[^\[\]\(\)\{\}]/', '', $expression); | |
do { | |
$bracketsRemaining = preg_replace('/\[\]|\(\)|\{\}/', '', $brackets); | |
} while ($brackets != $bracketsRemaining && $brackets = $bracketsRemaining); | |
$flag = $brackets ? 'Не верно ' : 'Верно '; | |
echo "$flag: $expression" . PHP_EOL; | |
} | |
// @note Test #1 (select query for search non unique rows) | |
// SELECT id, COUNT(id) len FROM `some_table` GROUP BY id HAVING len > 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment