Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an array via querystring

Status
Not open for further replies.

karren

Programmer
Feb 26, 2002
42
CA
hello all,

i have a variable that stores an array and i want to pass it to a new page using a querystring. any ideas on how to do that?

thanks,

karren
 
In general, that's not a good idea because there are limits to the amount of data you can transmit on the URL. Pass that (and the limit varies by OS and web server) and you may have problems.

If both scripts are on the same machine and under the same domain name, why not use session variables?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Code:
function parse_array_to_query_string ($array,$site)
{
  $st = $site;
  if (count($array) > 0)
  {
    $st .= "array0=" . $array[0];
  }
  foreach ($array as $key=>$value)
  {
    if ($key != 0)
    {
      $st .= "&array" . $key . "=" . $value;
    }
  }
  return $st;
}

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
You could also try a serialize plus a urlencode, followed by a urldecode and an unserialize.

That would save you the troubles of multidimensial arrays, and arrays which store objects.

But you're not going to get around the issues sleipnir brought up.
 
thanks for your replies everyone :)

it's strange because when i pass the array through the URL, the page that prints the array prints the correct amount of values stored in the array. but instead of priniting out what those values are, it only prints out:

Array
Array
Array

(it's correct that there are 3 array values stored in the array)

here's the code that's printing out the array which is passed through the url:

<?php

$EmailAddress2[]=$HTTP_GET_VARS["EmailAddress2"];

for($i=0;$i<count($EmailAddress2);$i++)
{
echo($EmailAddress2[$i]."<br />");
}

?>
 
Try "print_r( $yourarray );"
or "print serialize( $yourarray );"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top