0) { // already in sub-array? $subarr[$in_subarr][] = $tok; if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component $res[] = $this->strToArray(implode(',', $subarr[$in_subarr])); $in_subarr--; } } elseif ($tok{0} === '{') { // we're inside a new sub-array if ('}' !== substr($tok, -1, 1)) { $in_subarr++; // if sub-array has more than one element $subarr[$in_subarr] = array(); $subarr[$in_subarr][] = $tok; } else { $res[] = $this->strToArray($tok); } } else { // not sub-array $val = trim($tok, '"'); // remove " (surrounding strings) // perform type castng here? $res[] = $val; } } return $res; }