public static function toArray(array $arr, $level = 0)
    {
        foreach ($arr as $k => $v) {
            $arr[$k] = (is_array($v) ? self::toArray($v, 1) : '"' . addcslashes($v, '"\\') . '"');
        }

        if ($level === 0) {
            return "'" . pg_escape_string("{" . join(',', $arr) . "}") . "'";
        } else {
            return pg_escape_string("{" . join(',', $arr) . "}");
        }
    }