Is it possible to make an array a session variable in PHP?
The situation is that I have a table (page 1) with some cells having a link to a particular page. The next page will have a list of names (page 2, which I want to keep in a session array) with their respective checkboxes. On submitting this form, it will lead to a transaction page (page 3, where values of posted checkboxes are kept in a database for corresponding names). Now, if I return to the first page and click another cell, will the session array contain the new list of names or the old ones?
Yes, PHP supports arrays as session variables.
session_start(); // start up your PHP session! $_SESSION['userdata'] = $userqty; print_r($_SESSION['userdata']); print_r($userqty;); $userqty_total=array_sum($userqty);
Before you can store any information in session variables, you must first start up the session. To begin a new session, simply call the PHP session_start() function. It will create a new session and generate a unique session ID for the user. The PHP code in the example below simply starts a new session.
$this->session->userdata('property_id') would return the entire array stored in the session for the 'property_id' variable. All you need to do after that is access the elements like a regular PHP array. Code: $value = $this->session->userdata('property_id');
Yes, PHP supports arrays as session variables. See this page for an example.
As for your second question: once you set the session variable, it will remain the same until you either change it or unset
it. So if the 3rd page doesn't change the session variable, it will stay the same until the 2nd page changes it again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With