3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $the_data = [2,"(){[]()}","([)]"]; function getbalance($values){ $result = array(); for($l=1;$l<=$values[0];$l++){ $balance = array(); $value = $values[$l]; for($i=0; $i < strlen($value); $i++){ if( $value[$i] == "(" || $value[$i] == "{" || $value[$i] == "[" ){ $balance[] = $value[$i]; }elseif( $value[$i] == ")" ){ if( array_pop($balance) !== "(" ){ break; } }elseif( $value[$i] == "}" ){ if( array_pop($balance) !== "{" ){ break; } }elseif( $value[$i] == "]" ){ if( array_pop($balance) !== "[" ){ break; } } } if( count($balance) == 0 ){ $result[] = "YES"; }else{ $result[] = "NO"; } } return $result; } echo "Result:\n"; // echo array_pop($the_data); var_dump(getbalance($the_data));
based on 2kZul
Output for 5.6.0 - 5.6.30, hhvm-3.12.14 - 3.17.3, 7.0.0 - 7.3.0rc2
Result: array(2) { [0]=> string(3) "YES" [1]=> string(2) "NO" }