Re: Pass an array using GET or POST?

From: Date: Thu, 22 Jun 2000 20:55:37 +0000
Subject: Re: Pass an array using GET or POST?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2728@lists.php.net to get a copy of this message
At 05:36 PM 6/22/00 -0600, Scott S. Nicholson wrote: >Is there any way to pass an array from one page to another using GET or >POST? There may be an easy way around this, but here's what I've done in the past: <? // Note that the array can be defined any way and can be of any size. // The lines below are only for this example. $MyArray[0] = "Apples"; $MyArray[1] = "Oranges"; $MyArray[2] = "Grapes"; $MyArray[3] = "Peaches & Pears"; // Now find out the size of the array. $Size = sizeof($MyArray); // Now run through a WHILE loop to go through each array item. $Counter = 0; WHILE ($Counter < $Size) { // IT IS VERY IMPORTANT TO RAWURLENCODE() EACH ARRAY ITEM. If you don't, a // value such as "Peaches & Pears" will louse up the URL. $MyArrayEncoded[$Counter] = RAWURLENCODE($MyArray[$Counter]); // This loop will print HIDDEN INPUT tags for the use of form. You can also // combine them togeter in a string to make an <A HREF= > tag. Whatever. PRINT "<INPUT TYPE=HIDDEN NAME=MyArray[$Counter] VALUE=\"$MyArrayEncoded[$Counter]\">"; $Counter++; } ?> The rsulting form will look something like: <INPUT TYPE=HIDDEN NAME=MyArray[0] VALUE="Apples"> <INPUT TYPE=HIDDEN NAME=MyArray[1] VALUE="Oranges"> <INPUT TYPE=HIDDEN NAME=MyArray[2] VALUE="Grapes"> <INPUT TYPE=HIDDEN NAME=MyArray[3] VALUE="Peaches%20%26%20Pears"> When it goes to another PHP script, it will create an array named $MyArray and populate the first 4 values with the ones you sent. Hope this helps, -Jeff Gannaway

« previous php.general (#2728) next »