Jump to content

Passing An Array As Request Parameter To PHP


arpit_gadle

Recommended Posts

thnx for replying...

      wat i m asking is

             

 var array=new array()
                array[0]="First";
                array[1]="Second";

 

and want to pass this as single(array) request parameter to PHP script.

thnx for replying...

      wat i m asking is

             

 var array=new array()
                array[0]="First";
                array[1]="Second";

 

and want to pass this as single(array) request parameter to PHP script.

 

The easiest way is still going to be a URL, although you'll need to construct the parameters from your array.  Using your example:

http://host.com/script.php?array[]=First&array[]=Second

 

In your PHP script, $_GET['array'] would then be a PHP array, containing the values "First," and "Second."

 

Please note that it doesn't need to be named "array."  You can name it whatever you like.  The important thing is the [] at the end of your URL parameters.

The thing about GET parameters is they are not (afaik) capable of multi-dimensional values, such as arrays. You could potentially use a cookie, or store in sessions, or a database, but only the later is actually capable of handling an array as an array, and not as just values that can later be constructed into an array.

The thing about GET parameters is they are not (afaik) capable of multi-dimensional values, such as arrays.

 

um yeah you can eg

 

?foo[]=test&foo[bar]=baz&foo[bar][baz]=foo

 

Array

(

[0] => test

[bar] => Array

(

[baz] => foo

)

 

)

 

Also, you could send the javascript object as a json string and then decode it server side rather quickly and without having to loop through the array in javascript to construct the proper url

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.