I need to load a value from a recently posted page...

for ($i=0; $i<10; $i++)
     $_SESSION['someVar'][$i] = $_POST['someVar'][$i]
     $_SESSION['anotherVar'][$i] = $_POST['anotherVar'][$i]
     $_SESSION['yetAnotherVar'][$i] = $_POST['yetAnotherVar'][$i]

now the session part works just fine, but the $_POST part just blows up on me! How can I fix this? I want to keep the $_POST there, because I know I can just do $someVar[$i] and that will work but it's not what I want to do. I have seen a foreach loop and thought about that. But, would that keep all the variables tied together with the same index? I really dont want to use a foreach loop if I dont have to, but if thats what I need to use, then so be it.


$_SESSION['someVar'][$i] = $_POST['someVar'][$i]

$_POST[$i] is not valid unless your 'someVar' FORM element is an array of checkboxes or you have multiple text fields with the same name. Normally, it would just be $_POST.

Whether it is an array or not, you can just do this:

$_SESSION['someVar'] = $_POST['someVar'];

It does not matter whether 'someVar' is an array or not--the session var will still receive the value.

How about this?

$_SESSION['someVar'][$i] = $_POST['someVar'.$i]

In this case, your form variables are someVar1, someVar2,...

This article has been dead for over six months. Start a new discussion instead.