Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get php array from jquery serialize function sended value

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?

like image 497
Simon Avatar asked Feb 26 '26 20:02

Simon


1 Answers

Use parse_str():

parse_str($_POST['data'], $my_post);
like image 150
Barmar Avatar answered Mar 01 '26 11:03

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!