title: PHP good simple way to split the session variables into groups of values?
body: <p>I want to save part of the session into a big text field in a database table, after serializing it. Currently putting the session variables into an array seems to work, but I was wondering if there is a better way to define exactly which data is saved. I don't really want to end up with like a 4D array at some point, if I need to split up the session into multiple groups at the same time while also having sets of data stored as normal array in it. </p>
  
  <p>For example if I want to save $_SESSION["client_gender"] to the db, but not all the other session stuff like user login status. I put the client set of data into an array, so that I can serialize and save only the client array: $_SESSION["clients"]["client_gender"]. </p>
  
  <pre><code>$_SESSION["clients"]["group_1"]["client_gender"] = $_POST["client_gender"]; //some input from the user
  
  function save_client(){
  global $db;
  
  if(isset($_SESSION["client_id"]) &amp;&amp; $_SESSION["clients"]){
      $clients = serialize($_SESSION["clients"]);
      $query = "UPDATE clients SET clients = '{$clients}' WHERE id = {$_SESSION["client_id"]}"; //I know it's a bit confusing that a column has the same name as the table
      $result = mysqli_query($db, $query);
  }
  }
  
  // sometimes later when we want to use that client gender
  function load_client(){
  if(isset($_SESSION["client_id"])){
      $client = find_client_by_id($_SESSION["client_id"]); //just returns one row with a specific id from the clients table
      $_SESSION["clients"] = unserialize($client["clients"]);
  }
  }
  echo $_SESSION["clients"]["group_1"]["client_gender"];
  </code></pre>
  
  <p>Is there another way to tag certain data as 'clients' and others as 'group_1', that may or may not overlap? They also need to be able to go in and out of a database as a group, without having to specifically insert each value in the DB and back to the session. </p>