Array in session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Array in session (/showthread.php?tid=21494) |
Array in session - El Forum - 08-11-2009 [eluser]ThiagoPHX[/eluser] Hello guys, i'm trying to add arrays in the sessions. Like an e-commerce i add one product Code: $this->session->set_userdata(array('product_id', $id)); Than, in other page if the user add a new product, i'll need to add this product_id too. Thanks Array in session - El Forum - 08-11-2009 [eluser]Dam1an[/eluser] You'd need to get the array as a var from the session, add the item to the array and then put it back Here is a simplified example from a project I'm currently working on Code: $recent_hotels = $this->session->userdata('recent_hotels'); If fetching the array from the session returns false, that key doesn;t exists, so we create the array, otherwise, just add to it, and then write it back to the session Array in session - El Forum - 08-11-2009 [eluser]Jay Logan[/eluser] If you are simply trying to add an array to a session, you can do it by assigning the array to a variable, then add the variable to the session. IE: Code: $product_ids = array('1', '2', '3', '4'); Array in session - El Forum - 08-11-2009 [eluser]ThiagoPHX[/eluser] [quote author="Dam1an" date="1250034642"]You'd need to get the array as a var from the session, add the item to the array and then put it back Here is a simplified example from a project I'm currently working on Code: $recent_hotels = $this->session->userdata('recent_hotels'); If fetching the array from the session returns false, that key doesn;t exists, so we create the array, otherwise, just add to it, and then write it back to the session[/quote] Thanks !!! Is exactly what i need. Array in session - El Forum - 08-12-2009 [eluser]Dam1an[/eluser] You're welcome |