for using an api , I created json file with this data in js:
{
"name[0]": "foo",
"name[1]": "bar"
}
but after I posted it with jquery $.post
function to my php file , its converted like this: output with print_r();
Array
(
[name] => Array
(
[0] => foo
[1] => bar
)
)
but i need them to be key, not an array:
Array
(
[name[0]] => foo
[name[1]] => bar
)
how can I prevent that from converting to array?
{"[name[0]]":"foo","[name[1]]":"bar"}
is the correct syntax. Errors in your example:
You can generate this yourself at https://de.functions-online.com/json_encode.html using the following input:
array(
"[name[0]]" => "foo",
"[name[1]]" => "bar"
)
You can verify the result at https://de.functions-online.com/json_decode.html