I make a AJAX call, and sends the argument equal to forms's serialize-d value.
var form_data= $('#some-form').serialize();
var data = {
action: 'my-action',
data: form_data
};
$.post(my-file.php,data...){...}
So in my php file var I have a $_POST['data'] = arg1=value1&arg2[arg2_1]=value2... and so on.
It can be a long string with unlimited number of arguments and unlimited depth level.
So the question - is there any function in php, to make such string to an Associative array like this
$my_post[arg1]=value1;
$my_post[arg_2][arg2_1]=value2;
...
Or I need to write that function myself?
asked Sep 29, 2013 at 21:34
Simon
23.2k36 gold badges95 silver badges123 bronze badges
-
1Does that question help you? stackoverflow.com/questions/16003122/…TheWolf– TheWolf2013年09月29日 21:37:30 +00:00Commented Sep 29, 2013 at 21:37
-
1Unfortunately - no. I have to send the data exactly by described way.Simon– Simon2013年09月29日 21:39:21 +00:00Commented Sep 29, 2013 at 21:39
-
What prevents you from doing it the way suggested in the other question?TheWolf– TheWolf2013年09月29日 21:42:23 +00:00Commented Sep 29, 2013 at 21:42
-
It is the piece of WordPress plugin, so the WordPress core structure prevents me :)Simon– Simon2013年09月29日 21:48:09 +00:00Commented Sep 29, 2013 at 21:48
2 Answers 2
Use parse_str():
parse_str($_POST['data'], $my_post);
answered Sep 29, 2013 at 21:43
Barmar
789k57 gold badges555 silver badges669 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use parse_str() as described here: PHP unserializing a JS serialized string of variables
answered Sep 29, 2013 at 21:45
geomagas
3,2901 gold badge19 silver badges28 bronze badges
Comments
default