Welcome to the second PHP coding puzzle !

You are given a string that contains only the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, and you need to write a PHP function that will determine whether the string is valid or not. A string is considered valid if all parentheses, brackets, and braces are closed in the correct order.

For example, the string “([]){}” is valid, because the parentheses, brackets, and braces are all closed in the correct order. However, the string “([)]” is not valid, because the parentheses are not closed in the correct order.

Here’s the function signature:

function isValid($s) {
  // Your code here
}

You can assume that the input string is non-empty and consists only of the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’.

The solution is already available in the next page 😉 Feel free to share with us your solution here in comments or Github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here