Skip to content

Instantly share code, notes, and snippets.

@soulcyon
Created November 22, 2012 20:24
Show Gist options
  • Save soulcyon/4132805 to your computer and use it in GitHub Desktop.
Save soulcyon/4132805 to your computer and use it in GitHub Desktop.
Arbitrary JSON to PHP QueryString
/**
* @author Sashank Tadepalli <[email protected]>
* @license Creative Commons Attribution 3.0 Unported License.
* @version 1.0
* @link http://dijjit.com/js/arbitrary-json-to-php-querystring/
*/
function toQueryString(obj,inner){
var build = "";
for( t in obj ){
if( !obj.hasOwnProperty(t) ) continue;
build += "&";
var temp = (inner ? inner + "[" + (!(obj instanceof Array) ? t : "") + "]" : t);
build += typeof obj[t] == "object" ? toQueryString(obj[t], temp) : temp + "=" + obj[t];
}
return build.substring(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment