Skip to content

Instantly share code, notes, and snippets.

@yoko
Created February 23, 2009 15:50
Show Gist options
  • Save yoko/69013 to your computer and use it in GitHub Desktop.
Save yoko/69013 to your computer and use it in GitHub Desktop.
(function($) {
$.phparam = function(o) {
var ret = {};
var root, tree = [];
$.each(o, function deep(k, v) {
if (!root) root = k;
else tree.push(k);
if (typeof v == 'object')
$.each(v, deep);
else {
var array = tree.length ? '['+tree.join('][')+']' : '';
ret[root+array] = v;
}
if (!tree.length) root = null;
tree.pop();
});
return $.param(ret);
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment