private static function toDotted($array, $prepend = '', $counter = 1)
 {
     $results = [];
     if ($prepend !== '') {
         $results['if (typeof ' . $prepend . ' === \'undefined\' || ' . $prepend . '.constructor === Array ) {' . $prepend . ' = {}}'] = ';';
     }
     foreach ($array as $key => $value) {
         if ($counter > 1) {
             $key = '["' . $key . '"]';
         } else {
             $results['if (typeof ' . $key . ' === \'undefined\' || ' . $key . '.constructor === Array) {' . $key . ' = {}}'] = ';';
         }
         if (is_array($value) && !empty($value)) {
             // check if this is meant to be value-only array without assoc keys (P.S. assoc key = field name)
             if (is_array($value) && (count($value) === 0 || array_keys($value) === range(0, count($value) - 1))) {
                 $results[$prepend . $key] = ' = ' . json_encode($value) . ';';
             } else {
                 $results = array_merge($results, self::toDotted($value, $prepend . $key, $counter + 1));
             }
         } else {
             if (is_array($value) && count($value) === 0) {
                 $results[$prepend . $key] = ' = ' . json_encode($value) . ';';
             } else {
                 if (is_string($value)) {
                     $results[$prepend . $key] = ' = "' . Client::escape($value) . '";';
                 } else {
                     $results[$prepend . $key] = ' = ' . Client::escape($value) . ';';
                 }
             }
         }
     }
     return $results;
 }