What is the proper way to add an array to a $_SESSION variable that already contains arrays in PHP?
For example I have a session variable:
$_SESSION['test']
Then I do this:
$_SESSION['test'] = array('sample' => '1', 'sample2' => 2);
THEN, I come back to this session data at a later date. How would I add another array to $_SESSION[‘test’] without destroying what was already in there?
Fetch the size of current value, if it’s 1 (means there is one array), then make a new array, which contains previous value from
testand add the new value. Then changetestvalue to this new two dimension array.Would look something like that:
Fast and simple. Oh, not so sure if this is “proper” way.