views:

233

answers:

3

How can I make something like this below work?

<?PHP

$_SESSION['signup_errors']['test1'];
$_SESSION['signup_errors']['test2'];
$_SESSION['signup_errors']['test3'];
$_SESSION['signup_errors']['test4'];

foreach ($_SESSION['signup_errors'] as $key => &$value) {
    echo $value;
}
?>

Warning: Invalid argument supplied for foreach()

+2  A: 

Ahh I got it, I didnt have the values set in this example, sorry

jasondavis
+1  A: 

You're pretty close, but your setup lines don't actually assign any values.

$_SESSION['signup_errors']['test1'] = 'value1';
Mark F
A: 

It means you haven't assigned $_SESSION['signup_errors'] a value, meaning there were no errors I guess. You should put the following line above the error-checking code:

$_SESSION['signup_errors'] = array();
yjerem