jamesjmann Posted April 4, 2011 Share Posted April 4, 2011 I was wondering if its possible to add new elements to anarray i have called "$_SESSION['error']" like this: <?php $_SESSION["errors"][] = "string"; ?> Because i have a whole bunch of if statements that check my registration form and currently, if an error is found, i add a new element to that array like this: <?php $_SESSION["errors"]["var"] = "string"; ?> Then i echo the form again with this: <?php Foreach ($_SESSION["error"] as $object => $value) { echo $value; } ?> which basically just echos error messages...but the thing is is that i have a LOT of fields and its getting tiring having to give each error a unique name. So is it possible to add new elements to this array like that? Do the array elements automatically get id's? Quote Link to comment https://forums.phpfreaks.com/topic/232616-declaring-session-arrays/ Share on other sites More sharing options...
kenrbnsn Posted April 4, 2011 Share Posted April 4, 2011 Sure it works. You can do that with any array. Instead of asking the question and waiting for a reply, it's easy enough to try it in a quick script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/232616-declaring-session-arrays/#findComment-1196468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.