0

I have an array, myData=[[1,2,3],[4,5,6],....,[..,..,..]] I want to post this to the server.

Usually, for a JS variable, I just put the variable into a textbox and then submit the form using JS. However, when I put the 2D array into a textbox, JS converts it to a string, such that it becomes a 1D array, which looks like: [1,2,3,4,5,6....]

I want to be able to post the entire 2D array to the server and retrieve it on the next page using PHP. How do I do that?

Thanks!

0

1 Answer 1

1

You should use JSON to turn the array into a string with javascript and then parse the string back into an array in php.

for example:

var myData = var data = [['hooray',1],['test','meow'],[0,3,2]];
var myData_string = JSON.stringify(myData);

This will turn your object/array into a string which you can then POST and parse with php like so:

$myData = json_decode($input);

References:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.