Jump to content

Passing multidimensional arrays through post/get


janroald

Recommended Posts

Not sure if this is the right forum-cathegory, but heck...

 

//Examplified vars
<input type="hidden" name="foo[]" value="bar1">
<input type="hidden" name="foo[foomatic][]" value="bar2">
<input type="hidden" name="foo[foomatic][]" value="bar3">
<input type="hidden" name="foo[foomatic][bar][]" value="bar4">
<input type="hidden" name="foo[foomatic][bar][]" value="bar5">

 

print_r

 

Array
(
    [0] => bar1
    [foomatic] => Array
        (
            [0] => bar2
            [1] => bar3
            [bar] => Array
                (
                    [0] => bar4
                    [1] => bar5
                )

        )

)

 

Anyone knows when this feature was supported, or to what extent it is supported?

Tested on FF/IE6  POST/GET Apache/PHP4

 

 

Link to comment
Share on other sites

I have no clue, does it work? If so what is the question?

 

Yes, it works in the context I mentioned in the start post.

The question is really to what extent this works.

In "old" times I used the [] way to transfer arrays, but I had no idea it worked with multidimensional ones too. Serializing data was, to my knowledge, the best way to transfer such data between pages, of course until sessions became an option, as "mjlogan" points out.

This way one can access all form data through only one array variable. A huge workload has been lifted from me with this.

What makes this work? Is it the browser, webserver or PHP? 

Link to comment
Share on other sites

Obviously, the webserver/scripting language does it's part too. Since an array variable is created in php from a form string.

I'm sure this couldn't be done earlier at some point, since we used serializing to get it done.

Link to comment
Share on other sites

The webserver always has something to do with it, unless javascript can handle that type of data, than that is browser compatibility no? But yea, one way or the other this would NOT be possible period without some type of webserver and or language to power it. I think that goes without saying.

Link to comment
Share on other sites

Seems we kind of agree then.

My question still stands.

Does this way of passing multidimensional arrays work with all common webservers/browsers/languages? Is it a standardized way to pass multidimensional arrays?

 

I'm googling and googling, but can't seem to find references to this anywhere. Just plain old [] to send an array. Cant seem to find examples of anyone doing name="foo[bar]", which will make the array assosiative, much less name="foo[bar][]" which will make it multidimensional.

 

If this is now standard behaviour there are huge advantages to benefit from it.

Link to comment
Share on other sites

I understand what you mean.

 

What I am saying is that if the input above can be accessed from Javascript, chances are most webhosts/languages support the multi-dimensional array return from an input field. That is why I said do a test with Javascript and see if Javascript can access the multi-dim array.

Link to comment
Share on other sites

Js cant access any array since there exists no array in the input fields, only pure text. Of course js can parse the text an build it's own array, but that proves nothing.

Unless you can provide an example of what your intensions are, I can only understand that what you are trying to say makes no sense at all.

In essence, the example I started with at first, will be sent to the server like this text string :

?foo%5B%5D=bar1&foo%5Bfoomatic%5D%5B%5D=bar2&foo%5Bfoomatic%5D%5B%5D=bar3&foo%5Bfoomatic%5D%5Bbar%5D%5B%5D=bar4&foo%5Bfoomatic%5D%5Bbar%5D%5B%5D=bar5

 

in php then :

 

$_REQUEST[foo] now contains the array parsed from that text string.

Whether js can access anything, has nothing to do with it at all.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.