Create JSON with same elements in PHP -


i might missing obvious possible create json json_encode?

{     'foo': 'bar',     'foo': 'baz' } 

update

i had note start i'm aware i'm asking smells bad. solr requiring. see http://wiki.apache.org/solr/updatejson

no, json_encode won't give result duplicate keys, since object/array you're encoding cannot have had multiple values 1 property/key, store same data couple different ways. natural probably:

{     "foo": ["bar", "baz"] } 

you like:

[    {       "key": "foo",      "value": "bar"    },     {       "key": "foo",      "value": "baz"    } ] 

if must obtain syntax solr, can obtain combining multiple calls json_encode, although isn't pretty:

$foo1 = [ 'foo' => 'bar' ]; $foo2 = [ 'foo' => 'baz' ];  echo rtrim( json_encode( $foo1 ), '}' ) . ',' . ltrim( json_encode( $foo2 ), '{' ); // {"foo":"bar","foo":"baz"} 

Comments