laqutus Posted March 23, 2009 Share Posted March 23, 2009 How can I create a session array populate it with only one item (id), and then add other items without overwiring the original session? foreach ( $_POST as $key) { echo $key; echo "<br>"; $_session['cart'][] = $key; }?> <? // Attempt to add values into session array echo '<pre>'; print_r($_session); echo '</pre>'; ?> This will take in the one bit of date but is overwritten if I add anything new to it, how can I increment the session array to hold more data (like new row in mysql). The problem is because I could create a new mysql table and have a temporary cart, but flushing the temporary orders (not completed) order would be a pain so I thought it better to create a session array, is this good practice? Cheers Sarah Quote Link to comment https://forums.phpfreaks.com/topic/150734-session-array/ Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 you just assign whatever value you want to a new index $_SESSION['ID'] = "foo"; $_SESSION['stuff'] = "bar"; $_SESSION['hi'] = "!!!"; Quote Link to comment https://forums.phpfreaks.com/topic/150734-session-array/#findComment-791904 Share on other sites More sharing options...
laqutus Posted March 23, 2009 Author Share Posted March 23, 2009 Ok cool, I understand that, thanks loanwolf, but how do I increment the new index? This is the bit im having trouble with, as If i make the index a variable then it does not seem to work as IO dont know how to check if the index already exists. I want the index to be numerical eg: $_SESSION['1'] = "foo"; $_SESSION['2'] = "bar"; $_SESSION['3'] = "!!!"; Quote Link to comment https://forums.phpfreaks.com/topic/150734-session-array/#findComment-791906 Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 I honestly dont know if $_SESSION can be a multidimensional array, since what you are trying to do is something like this i think $_SESSION[iD][value] to check if a session is set though, all you have to do is if (isset($_SESSION['1'])) { //do something } Quote Link to comment https://forums.phpfreaks.com/topic/150734-session-array/#findComment-791912 Share on other sites More sharing options...
wildteen88 Posted March 23, 2009 Share Posted March 23, 2009 I dont think $_SESSION can be a multi-dimensional array ? Yes $_SESSION can be multi-dimensional. It is the same as any other array Quote Link to comment https://forums.phpfreaks.com/topic/150734-session-array/#findComment-791916 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.