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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Arrays across pages

Status
Not open for further replies.

flea333

Technical User
Sep 4, 2003
47
US
I need to pass an array to the same page as it refreshes, I don't want to have to load the array every time the page loads. Is there a way to do this?
 
I don't understand. The array would have to be loaded from somewhere, even if from a session variable store on the server's filesystem.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
This is what I do: I read file names in a directory and store them in an array, then I want to pass that array over to the next page like the same way you submit variables from a form to another page.
 
either make the array a global variable or serialize it and pass it thru the page form elements and unserliaze at the other end

Bastien

Cat, the other other white meat
 
How do I pass an array over? I believe the array is global because I declared it outside any functions.
 
Global" in this context only applies to variables within a single script. It doesn't mean that the variable carries over to other scripts or even to multiple runs of a single script.

Unless, of course, that the variable is a session variable.

You could also apply Bastien's solution of serializing the array and embedding it in the form on your page your script produces. That serialization will then be passed to the subsequent script when the form is submitted.

That subsequent script can then unserialize the array and have the values available.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
one way
Code:
for ($i =0; $i<20; $i++)
{
	$_SESSION['somearray'][$i] = "-1";
}

you now have 20 vars to use later
Code:
$j =0;
for ($i =0; $i<20; $i++)
{
   if (i am true)
   {
	$_SESSION['somearray'][$j++] = "some value";
   }
         
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top