At times, I have need to push all submitted form array values into $_SESSION. To do this, I've written a small function:
function addPostToSession() {
foreach ($_POST as $key=>$value ){
$_SESSION[$key]=stripslashes(strval($value));
}
}
This works well, as long as $_POST is one dimensional, but in a form with checkboxes, $_POST may contain arrays as array elements.
Example:
POST: Array
(
[othertype] => Server
[issues] => Array
(
[0] => crashes
[1] => freezes
)
)
When I use my addPostToSession() function, $_SESSION['issues'] is given the string 'Array' (checked with var_dump).
Example:
SESSION: Array
(
[othertype] => Server
[issues] => Array
)
Is there a preferred way to gather array values into $_SESSION without using implode or some other array-to-string function?
Thanks in advance,
-Ray