Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created July 20, 2013 14:40
Show Gist options
  • Select an option

  • Save hokaccha/6045280 to your computer and use it in GitHub Desktop.

Select an option

Save hokaccha/6045280 to your computer and use it in GitHub Desktop.
var qs = require('querystring')
console.log(qs.parse('foo=1&foo=2'));
//=> { foo: [ '1', '2' ] }
console.log(qs.parse('foo[]=1&foo[]=2'));
//=> { 'foo[]': [ '1', '2' ] }
<?php
parse_str("foo=1&foo=2");
var_dump($foo);
//=> string(1) "2"
parse_str("foo[]=1&foo[]=2");
var_dump($foo);
//=>
// array(2) {
// [0]=>
// string(1) "1"
// [1]=>
// string(1) "2"
// }
require 'rack'
p Rack::Utils.parse_query 'foo=1&foo=2'
#=> {"foo"=>["1", "2"]}
p Rack::Utils.parse_query 'foo[]=1&foo[]=2'
#=> {"foo[]"=>["1", "2"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment