How to pass arrays from one document to the other?
Moderator: General Moderators
-
TheDumbNerd
- Forum Newbie
- Posts: 13
- Joined: Sun Nov 13, 2011 4:01 pm
How to pass arrays from one document to the other?
If i had a value that the user had entered into my form on a form page, how do you pass that value onto another page where it is dispayed in a table? Like it gets validated on one page, lets called it the process page. If the values that the user hadentered into the form are legal, then you get redirected to a main page where thedata that the userJUST ENTERED is displayed in a table.
Re: How to pass arrays from one document to the other?
You load into a string and put each array in it together with a : and then split the : back into an array.
Re: How to pass arrays from one document to the other?
Someone correct me if I'm wrong (as I have never tried it) but can't an array be stored in $_SESSION['value']?
I use $_SESSION for passing single variables between scripts but I thought it could be used for arrays as well.
I use $_SESSION for passing single variables between scripts but I thought it could be used for arrays as well.
-
mikeashfield
- Forum Contributor
- Posts: 159
- Joined: Sat Oct 22, 2011 10:50 am
Re: How to pass arrays from one document to the other?
Code: Select all
<?php
// begin the session
session_start();
// create an array
$array_names=array('mike', 'sarah', 'jake', 'liam');
// put the array in a session variable
$_SESSION['names']=$array_names;
// a little message to say we have done it
echo 'Putting array into a session variable';
?>Code: Select all
<?php
// begin the session
session_start();
// loop through the session array with foreach
foreach($_SESSION['names'] as $key=>$value)
{
// and print out the values
echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
}
?>