View Full Version : array

03-09-2007, 09:13 PM
I'm trying to pass an array from one page to another and display it's contents on the next page.

This is the code I am using

$var1 = $_GET["name"];

foreach($var1 as $value)

echo $value;

I keep getting this error "Warning: Invalid argument supplied for foreach() in..\..\..\..\..."

Any ideas?

03-09-2007, 09:25 PM
$var1 = $_GET["name"];

are u sure $var1 is an array?

03-09-2007, 09:48 PM
i passed an array in the form action of a form using this line


where $array is an array in the page it is sent from

is it possible to send an array this way
and is there a way of checking if it is an array on the pg it is sent to?

foreach is not working for me


03-09-2007, 09:58 PM
Doing this:

$array = array(1, 4, 3, 4);
$url = "index.php?array=".$array;
echo $url;

Will not work. You cannot pass an array that way.

You should consider using sessions, or perhaps try this depending on what is in the array:

Page 1:

$array = array(1, 4, 3, 4);
$url = "index.php?array=".urlencode(implode(', ', $array));
echo $url;


$array = explode(',', urldecode($_GET['array']));

03-09-2007, 10:03 PM
http requests are sent as text not as php objects...

"deleted.php?name=" . implode(',', $array)

and when u get it back

$var1 = $_GET["name"];
$arr = explode(',', $array);

foreach should now work on $arr