Pass 2D array from Webpage to PHP page VIA jQuery or JS

Javascript coding ..

Moderators: macek, egami, gesf

Markmax33
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Apr 09, 2012 12:54 pm

Pass 2D array from Webpage to PHP page VIA jQuery or JS

Postby Markmax33 » Mon Apr 09, 2012 12:59 pm

What is the proper syntax for for defining a multidimensional array in jQuery or Javascipt? I want to pass it to a php file through the $.post after it is defined properly. Do I need a nested map() function or something else like serialize? The arrays are all integers if that matters!


I have a bunch of text input boxes that all feed into a multidimensional array for processing in a PHP file:

<input type="text" size="4" value="" name="floor_areas[0][5]">
<input type="text" size="4" value="" name="floor_areas[1][5]">
<input type="text" size="4" value="" name="floor_areas[2][5]">

<input type="text" size="4" value="" name="floor_areas[0][4]">
<input type="text" size="4" value="" name="floor_areas[1][4]">
<input type="text" size="4" value="" name="floor_areas[2][4]">

etc...

I used this code to get single dimensioned array:

var main_occupancy = $('input[name="main_occupancy\\[\\]"]:checked').
map(function(i, elem) { return $(this).val(); }).get();

Thanks for any help!

User avatar
gandahar
New php-forum User
New php-forum User
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am

Re: Pass 2D array from Webpage to PHP page VIA jQuery or JS

Postby gandahar » Fri Apr 27, 2012 5:15 pm

Code: Select all

var myArray = new Array();

myArray[0] = new Array(1,2,3);
myArray[1] = new Array(4,5,6);
//etc...


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 2 guests

cron