function filterEquationBrackets($q) { $serializedEquation = serializeEquationToArray($q); $equation = deserializeArrayToEquation($serializedEquation); $filteredSerializedEquation = filterBracketBySerializedEquation($serializedEquation); return deserializeArrayToEquation($filteredSerializedEquation); }
function deserializeArrayToEquation($serializedEquation) { // init $equation = ''; // process foreach ($serializedEquation as $c) { // recursive to get characters if $c is array if (is_array($c)) { $equation .= deserializeArrayToEquation($c); continue; } // get character $equation .= $c; } return $equation; }