Page 1 of 1

[SOLVED] list() with array in the Session?

Posted: Mon Aug 30, 2004 11:20 am
by dashifen
Greetings!

As part of a form-validation page I'm writing, I stuck the previously entered form data into the session when an error was encountered so that I can extract said data after redirecting to the form page and place it into the correct form fields. In the past I've always had lines like this:

Code: Select all

$title = $_SESSION['event_details']['title'];
$start_date = $_SESSION['event_details']['start_date'];
And the like. However, it occured to me today that I could probably perform a similar task with the list() construct. I tried this:

Code: Select all

list($title, $start_date) = $_SESSION['event_details'];
But received an error saying that there I had attempted to access an invalid offset (or something like that). I assumed that that meant that list() couldn't extract the values of the array within the $_SESSION array.

Any ideas on how to do get at those values with list()? If I use print_r() I can display them on the screen, so I know they're in there. Could it be that the array is associative and therefore doesn't have numerical indices? If so, anyone got a good way to convert associative to "normal" arrays or is there a list() construct that works on associative arrays?

Thanks!
-- Dash --

Posted: Mon Aug 30, 2004 11:21 am
by markl999
Try:

Code: Select all

list($title, $start_date) = each($_SESSION['event_details']);

Posted: Mon Aug 30, 2004 11:22 am
by feyd
try

Code: Select all

list($title,$start_date) = array_values($_SESSION['event_details']);

Posted: Mon Aug 30, 2004 11:46 am
by dashifen
feyd wrote:try

Code: Select all

list($title,$start_date) = array_values($_SESSION['event_details']);
This works.

Thanks!!!